"ui";
// 安卓库
importClass(android.graphics.Color);
importClass(android.graphics.drawable.GradientDrawable);
// 导入库
const project = require('./project.json');
var storage = storages.create("autotouchShijieXy");

// 开发配置
var isPulic = true;
var lmNontinue = 15;
// 固定数据
var colorHei = "#333333"
var hong = "#E63F31";
var gamePackageName = "com.qqgame.mic";
var gameActivity = "com.qqgame.mic.YXSMainActivity";
var myThreads;
var floatyWindow; // 悬浮窗
var floatyConsole; // 日志悬浮窗
var myLogStr = ""; // 重写打印
var appVersions = project.versionName;   //版本号
// 修改数据
var dixiTishi = true;
var runagain = false; // 是否截图权限申请
var shouyejinru = false; // 是不是从游戏首页进入
var xiaobingbuzu = false; // 小兵不足
var secureNum = 5; // 容错次数 避免死循环
var caijiduiwu = 0; // 采集队伍
var dayeduiwu = 0; // 打野队伍
var duiwushangxian = 3; // 队伍上限
var qqAccountName = ''; // 必须qq 如果不是空 选定指定账号进行账号切换
var picJizhun = 1;
var picJizhunHeight = 1;
var deviceWidth = device.width;
var deviceHeight = device.height;
var youshangDuilie = {x: device.width-1000, y: 159, w: 1000, h: 80};
log('宽高：', deviceWidth, deviceHeight)

// 缓存数据
var delayBase = 1;
var yanchi = 500 * delayBase; // 点击后停顿
var yanchi1 = 1000 * delayBase; // 点击前停顿
var yanchi2 = 2000 * delayBase; // 点击后停顿
var yanchi3 = 3000 * delayBase; // 点击后停顿
var yanchi5 = 5000 * delayBase; // 点击后停顿
var shangciweizhi = {}; // 上次位置坐标
var xiaodituPosit = {}; // 小地图起始位置
var cunliangWeizhi = {}; // 存量起始位置
var yingxiongMsgWeizhi = {}; // 英雄信息坐标
var ziyuanZuobianWeizhi = {}; // 资源信息坐标
var toCaijiList = storage.get("caijiItems", [{ x: 66, y: 66, level: 1, type: 2 }, { x: 88, y: 88, level: 2, type: 1 }]); // 资源列表 坐标 等级 类型 粮木矿-123
// 联盟区域
// 93 61
var zuoshangList = [{"x":90,"y":64},{"x":80,"y":64},{"x":80,"y":56},{"x":90,"y":56},{"x":100,"y":56},{"x":100,"y":64},{"x":100,"y":72},{"x":90,"y":72},{"x":80,"y":72},{"x":70,"y":64},{"x":70,"y":56},{"x":70,"y":48},{"x":80,"y":48},{"x":90,"y":48},{"x":100,"y":48},{"x":110,"y":48},{"x":110,"y":56},{"x":110,"y":64},{"x":110,"y":72},{"x":110,"y":80},{"x":100,"y":80},{"x":90,"y":80},{"x":80,"y":80},{"x":70,"y":80},{"x":70,"y":72},{"x":60,"y":64},{"x":60,"y":56},{"x":60,"y":48},{"x":60,"y":40},{"x":70,"y":40},{"x":80,"y":40},{"x":90,"y":40},{"x":100,"y":40},{"x":110,"y":40},{"x":120,"y":40},{"x":120,"y":48},{"x":120,"y":56},{"x":120,"y":64},{"x":120,"y":72},{"x":120,"y":80},{"x":120,"y":88},{"x":110,"y":88},{"x":100,"y":88},{"x":90,"y":88},{"x":80,"y":88},{"x":60,"y":72},{"x":50,"y":64},{"x":50,"y":56},{"x":50,"y":48},{"x":50,"y":40},{"x":60,"y":32},{"x":70,"y":32},{"x":80,"y":32},{"x":90,"y":32},{"x":100,"y":32},{"x":110,"y":32},{"x":120,"y":32},{"x":120,"y":96},{"x":110,"y":96},{"x":100,"y":96},{"x":90,"y":96}]
// 62 124
var zuozhongList = [{"x":70,"y":128},{"x":60,"y":128},{"x":60,"y":120},{"x":70,"y":120},{"x":80,"y":120},{"x":80,"y":128},{"x":80,"y":136},{"x":70,"y":136},{"x":60,"y":136},{"x":50,"y":128},{"x":50,"y":120},{"x":50,"y":112},{"x":60,"y":112},{"x":70,"y":112},{"x":80,"y":112},{"x":90,"y":112},{"x":90,"y":120},{"x":90,"y":128},{"x":90,"y":136},{"x":90,"y":144},{"x":80,"y":144},{"x":70,"y":144},{"x":60,"y":144},{"x":50,"y":144},{"x":50,"y":136},{"x":40,"y":128},{"x":40,"y":120},{"x":40,"y":112},{"x":40,"y":104},{"x":50,"y":104},{"x":60,"y":104},{"x":70,"y":104},{"x":80,"y":104},{"x":90,"y":104},{"x":100,"y":112},{"x":100,"y":120},{"x":100,"y":128},{"x":100,"y":136},{"x":80,"y":152},{"x":70,"y":152},{"x":60,"y":152},{"x":50,"y":152},{"x":40,"y":152},{"x":40,"y":144},{"x":40,"y":136},{"x":40,"y":96},{"x":50,"y":96},{"x":60,"y":96},{"x":70,"y":96},{"x":80,"y":96},{"x":110,"y":112},{"x":110,"y":120},{"x":110,"y":128},{"x":110,"y":136},{"x":70,"y":160},{"x":60,"y":160},{"x":50,"y":160},{"x":40,"y":160},{"x":40,"y":88},{"x":50,"y":88},{"x":60,"y":88},{"x":70,"y":88},{"x":50,"y":168},{"x":40,"y":168},{"x":40,"y":80},{"x":50,"y":80},{"x":60,"y":80},{"x":40,"y":72},{"x":50,"y":72}]
// 84 187
var zuoxiaList = [{"x":90,"y":192},{"x":80,"y":192},{"x":80,"y":184},{"x":90,"y":184},{"x":100,"y":184},{"x":100,"y":192},{"x":100,"y":200},{"x":90,"y":200},{"x":80,"y":200},{"x":70,"y":192},{"x":70,"y":184},{"x":70,"y":176},{"x":80,"y":176},{"x":90,"y":176},{"x":100,"y":176},{"x":110,"y":176},{"x":110,"y":184},{"x":110,"y":192},{"x":110,"y":200},{"x":110,"y":208},{"x":100,"y":208},{"x":90,"y":208},{"x":80,"y":208},{"x":70,"y":208},{"x":70,"y":200},{"x":60,"y":192},{"x":60,"y":184},{"x":60,"y":176},{"x":60,"y":168},{"x":70,"y":168},{"x":80,"y":168},{"x":90,"y":168},{"x":100,"y":168},{"x":110,"y":168},{"x":120,"y":168},{"x":120,"y":176},{"x":120,"y":184},{"x":120,"y":192},{"x":120,"y":200},{"x":120,"y":208},{"x":120,"y":216},{"x":110,"y":216},{"x":100,"y":216},{"x":90,"y":216},{"x":80,"y":216},{"x":70,"y":216},{"x":60,"y":208},{"x":60,"y":200},{"x":50,"y":192},{"x":50,"y":184},{"x":50,"y":176},{"x":70,"y":160},{"x":80,"y":160},{"x":90,"y":160},{"x":100,"y":160},{"x":110,"y":160},{"x":120,"y":160},{"x":120,"y":224},{"x":110,"y":224},{"x":100,"y":224},{"x":90,"y":224},{"x":80,"y":224},{"x":50,"y":200},{"x":80,"y":152},{"x":90,"y":152},{"x":100,"y":152},{"x":110,"y":152},{"x":120,"y":152},{"x":90,"y":144},{"x":100,"y":144},{"x":110,"y":144},{"x":120,"y":144},{"x":100,"y":136},{"x":110,"y":136}]
// 165.61
var youshangList = [{"x":170,"y":64},{"x":160,"y":64},{"x":160,"y":56},{"x":170,"y":56},{"x":180,"y":56},{"x":180,"y":64},{"x":180,"y":72},{"x":170,"y":72},{"x":160,"y":72},{"x":150,"y":64},{"x":150,"y":56},{"x":150,"y":48},{"x":160,"y":48},{"x":170,"y":48},{"x":180,"y":48},{"x":190,"y":48},{"x":190,"y":56},{"x":190,"y":64},{"x":190,"y":72},{"x":180,"y":80},{"x":170,"y":80},{"x":160,"y":80},{"x":150,"y":80},{"x":150,"y":72},{"x":140,"y":64},{"x":140,"y":56},{"x":140,"y":48},{"x":140,"y":40},{"x":150,"y":40},{"x":160,"y":40},{"x":170,"y":40},{"x":180,"y":40},{"x":190,"y":40},{"x":200,"y":40},{"x":200,"y":48},{"x":200,"y":56},{"x":200,"y":64},{"x":170,"y":88},{"x":160,"y":88},{"x":150,"y":88},{"x":140,"y":88},{"x":140,"y":80},{"x":140,"y":72},{"x":130,"y":64},{"x":130,"y":56},{"x":130,"y":48},{"x":130,"y":40},{"x":130,"y":32},{"x":140,"y":32},{"x":150,"y":32},{"x":160,"y":32},{"x":170,"y":32},{"x":180,"y":32},{"x":190,"y":32},{"x":200,"y":32},{"x":210,"y":40},{"x":210,"y":48},{"x":210,"y":56},{"x":160,"y":96},{"x":150,"y":96},{"x":140,"y":96},{"x":130,"y":96},{"x":130,"y":88},{"x":130,"y":80},{"x":130,"y":72},{"x":130,"y":24},{"x":140,"y":24},{"x":150,"y":24},{"x":160,"y":24},{"x":170,"y":24},{"x":180,"y":24},{"x":190,"y":24},{"x":150,"y":104},{"x":140,"y":104},{"x":130,"y":104},{"x":140,"y":112},{"x":130,"y":112}]
// // 188.124
var youzhongList = [{"x":190,"y":128},{"x":180,"y":128},{"x":180,"y":120},{"x":190,"y":120},{"x":200,"y":120},{"x":200,"y":128},{"x":200,"y":136},{"x":190,"y":136},{"x":180,"y":136},{"x":170,"y":128},{"x":170,"y":120},{"x":170,"y":112},{"x":180,"y":112},{"x":190,"y":112},{"x":200,"y":112},{"x":210,"y":112},{"x":210,"y":120},{"x":210,"y":128},{"x":210,"y":136},{"x":210,"y":144},{"x":200,"y":144},{"x":190,"y":144},{"x":180,"y":144},{"x":170,"y":144},{"x":170,"y":136},{"x":160,"y":128},{"x":160,"y":120},{"x":160,"y":112},{"x":160,"y":104},{"x":170,"y":104},{"x":180,"y":104},{"x":190,"y":104},{"x":200,"y":104},{"x":210,"y":104},{"x":220,"y":104},{"x":220,"y":112},{"x":220,"y":120},{"x":220,"y":128},{"x":220,"y":136},{"x":220,"y":144},{"x":220,"y":152},{"x":210,"y":152},{"x":200,"y":152},{"x":190,"y":152},{"x":180,"y":152},{"x":170,"y":152},{"x":160,"y":144},{"x":160,"y":136},{"x":150,"y":128},{"x":150,"y":120},{"x":150,"y":112},{"x":170,"y":96},{"x":180,"y":96},{"x":190,"y":96},{"x":200,"y":96},{"x":210,"y":96},{"x":220,"y":96},{"x":220,"y":160},{"x":210,"y":160},{"x":200,"y":160},{"x":190,"y":160},{"x":180,"y":160},{"x":150,"y":136},{"x":180,"y":88},{"x":190,"y":88},{"x":200,"y":88},{"x":210,"y":88},{"x":210,"y":168},{"x":200,"y":168},{"x":190,"y":168},{"x":190,"y":80},{"x":200,"y":80},{"x":200,"y":176}]
// // 156.187
var youxiaList = [{"x":160,"y":192},{"x":150,"y":192},{"x":150,"y":184},{"x":160,"y":184},{"x":170,"y":184},{"x":170,"y":192},{"x":170,"y":200},{"x":160,"y":200},{"x":150,"y":200},{"x":140,"y":192},{"x":140,"y":184},{"x":140,"y":176},{"x":150,"y":176},{"x":160,"y":176},{"x":170,"y":176},{"x":180,"y":176},{"x":180,"y":184},{"x":180,"y":192},{"x":180,"y":200},{"x":180,"y":208},{"x":170,"y":208},{"x":160,"y":208},{"x":150,"y":208},{"x":140,"y":208},{"x":140,"y":200},{"x":130,"y":192},{"x":130,"y":184},{"x":130,"y":176},{"x":130,"y":168},{"x":140,"y":168},{"x":150,"y":168},{"x":160,"y":168},{"x":170,"y":168},{"x":180,"y":168},{"x":190,"y":168},{"x":190,"y":176},{"x":190,"y":184},{"x":190,"y":192},{"x":190,"y":200},{"x":190,"y":208},{"x":180,"y":216},{"x":170,"y":216},{"x":160,"y":216},{"x":150,"y":216},{"x":140,"y":216},{"x":130,"y":216},{"x":130,"y":208},{"x":130,"y":200},{"x":130,"y":160},{"x":140,"y":160},{"x":150,"y":160},{"x":160,"y":160},{"x":170,"y":160},{"x":180,"y":160},{"x":200,"y":176},{"x":200,"y":184},{"x":200,"y":192},{"x":200,"y":200},{"x":170,"y":224},{"x":160,"y":224},{"x":150,"y":224},{"x":140,"y":224},{"x":130,"y":224},{"x":130,"y":152},{"x":140,"y":152},{"x":150,"y":152},{"x":160,"y":152},{"x":170,"y":152},{"x":130,"y":144},{"x":140,"y":144},{"x":150,"y":144},{"x":160,"y":144},{"x":140,"y":136},{"x":150,"y":136}]

ui.layout(
    <drawer id="drawer" >
        <vertical>
            <appbar>
                <toolbar id="toolbar" title="世界模式 挂机辅助" />
                <tabs id="tabs" />
            </appbar>

            <viewpager id="viewpager">
                <ScrollView >
                    <frame>
                        <vertical padding="10sp" >
                            <horizontal>
                                <text text="公告：" textColor={hong} textSize="15sp" />
                                <text text="模拟器上出现进世界模式后闪退,请提高模拟器CPU核心数 " id="gonggaoa" textColor={hong} textSize="14sp" />
                            </horizontal>
                            <text text="红块区域,暂不开放" gravity="left" marginTop="6sp" />
                            {/* 主流程 */}
                            <horizontal marginTop="10sp" padding="8sp" bg="#99FE01">
                                <checkbox id="tianxuan" text="天选印记" />
                                <checkbox id="junbao" text="领取军报" />
                                <checkbox id="zhengshou" text="天选征收" />
                                <checkbox id="lingqurenwu" text="领取任务" />
                            </horizontal>
                            {/* 自动打野 */}
                            <vertical marginTop="8sp" padding="8sp" bg="#FFFF01">
                                <horizontal >
                                    <text text=" 是否开启：" textColor="#000000" textSize="15sp" />
                                    <checkbox id="isdaye" text="自动打野(默认全刷)" />
                                </horizontal>
                                <horizontal marginTop="2sp">
                                    <checkbox id="ye1" text="1" />
                                    <checkbox id="ye2" text="2" />
                                    <checkbox id="ye3" text="3" />
                                    <checkbox id="ye4" text="4" />
                                    <checkbox id="ye5" text="5" />
                                    <checkbox id="ye6" text="6" />
                                    <checkbox id="ye7" text="7" />
                                </horizontal>
                                <horizontal marginTop="2sp">
                                    <text text=" 保留前" textColor="#000000" textSize="14sp" />
                                    <input id="shuayebaoliu" text="0" textSize="16sp" inputType="number" padding="8 6" />
                                    <text text="个英雄不参与打野，用来备战和采集" textColor="#000000" textSize="14sp" />
                                </horizontal>
                                <vertical>
                                    <horizontal>
                                        <checkbox id="shuayewushang" textColor="#000000" text="忽略出兵战力不保留英雄(提升刷野速度)" />
                                    </horizontal>
                                    <horizontal>
                                        <text text=" 刷野出兵战力：" textColor="#000000" textSize="15sp" />
                                        <spinner id="shuayezhanli" entries="胜券在握|优势明显|胜算较高|胜算稍高|胜负各半" spinnerModer="dialog" />
                                    </horizontal>
                                    <horizontal>
                                        <checkbox id="centerZhucheng" />
                                        <text text="主城为中心" textColor="#000000" textSize="15sp" />
                                        <input text="1" id="centerNPing" textSize="16sp" inputType="number" padding="8 6" />
                                        <text text="屏内范围" textColor="#000000" textSize="15sp" />
                                    </horizontal>
                                    <horizontal>
                                        <checkbox id="caijiquyuDy" />
                                        <text text="采集坐标区域打野" textColor="#000000" textSize="15sp" />
                                    </horizontal>
                                    <horizontal>
                                        <checkbox id="zuoshang" text="左上联盟" />
                                        <checkbox id="zuozhong" text="左中联盟" />
                                        <checkbox id="zuoxia" text="左下联盟" />
                                    </horizontal>
                                    <horizontal>
                                        <checkbox id="youshang" text="右上联盟" />
                                        <checkbox id="youzhong" text="右中联盟" />
                                        <checkbox id="youxia" text="右下联盟" />
                                    </horizontal>
                                    <horizontal>
                                        <checkbox id="changfangxingDy" />
                                        <text text="坐标" textColor="#000000" textSize="15sp" />
                                        <input text="88,88,168,168" id="fangxingPing" textSize="16sp" inputType="number" padding="8 6" />
                                        <text text="内范围" textColor="#000000" textSize="15sp" />
                                    </horizontal>
                                </vertical>

                            </vertical>
                            {/* 升级建筑 */}
                            <vertical marginTop="8sp" padding="8sp" bg="#E43C2F">
                                <horizontal >
                                    <text text=" 是否开启：" textColor="#000000" textSize="15sp" />
                                    <checkbox id="shengjia" text="建筑升级" />
                                </horizontal>
                                <horizontal marginTop="2sp">
                                    <checkbox id="sjZhucdheng" text="主城" />
                                    <checkbox id="sjYingxiong" text="英雄" />
                                    <checkbox id="sjBingying" text="兵营" />
                                    <checkbox id="sjYanjiu" text="研究" />
                                </horizontal>
                                <horizontal>
                                    <checkbox id="sjChengfang" text="城防" />
                                    <checkbox id="sjSchang" text="市场" />
                                    <checkbox id="sjJunbei" text="军备" />
                                </horizontal>
                            </vertical>
                            {/* 其他设置 */}
                            <vertical marginTop="8sp" padding="8sp" bg="#FFC801">
                            <horizontal marginTop="2sp">
                                    <text text=" 是否检测登陆：" textColor="#000000" textSize="15sp" />
                                    <checkbox id="jaincedenglu" text="检测登陆" />
                                </horizontal>
                                <horizontal>
                                    <text text=" 登录方式：" textColor="#000000" textSize="15sp" />
                                    <spinner id="denglufangshi" entries="QQ登陆|微信" spinnerModer="dialog" />
                                </horizontal>
                                <horizontal>
                                    <text text=" 任务完成后：" textColor="#000000" textSize="15sp" />
                                    <spinner id="yunxingfangshi" entries="智能运行|循环运行|定时运行" spinnerModer="dialog" />
                                </horizontal>
                                <horizontal marginTop="2sp">
                                    <text text=" 定时运行-每隔" textColor="#000000" textSize="14sp" />
                                    <input id="intermission" text="0" textSize="16sp" inputType="number" padding="8 6" />
                                    <text text="小时自动运行" textColor="#000000" textSize="14sp" />
                                </horizontal>
                                <horizontal>
                                    <checkbox id="islingdidenglu" text="另地登陆重连等待" />
                                    <input text="18" id="lingdidenglu" textSize="16sp" inputType="number" padding="8 6" />
                                    <text text="分钟" textColor="#000000" textSize="15sp" />
                                </horizontal>
                            </vertical>

                        </vertical>
                    </frame>
                </ScrollView>
                {/* 采集设置 */}
                <ScrollView>
                    <frame>
                        <vertical padding="10sp">
                            <vertical bg="#99FE01" padding="8sp">
                                <horizontal >
                                    <text text=" 是否开启：" textColor="#000000" textSize="15sp" />
                                    <checkbox id="caijiziyuan" text="资源采集" />
                                </horizontal>
                                <checkbox id="zhicaifujin" text="采集附近资源不采集坐标资源" />
                                <checkbox id="beixuanziyuan" text="坐标资源不能采集时采集附近资源" />
                                <horizontal marginTop="1sp">
                                    <text text=" 附近" textColor="#000000" textSize="14sp" />
                                    <input id="beixuanziyuanFw" text="2" textSize="16sp" inputType="number" padding="8 6" />
                                    <text text="屏之内" textColor="#000000" textSize="14sp" />
                                </horizontal>
                                <checkbox id="baohanziji" text="可采集自己领地资源" />
                                <checkbox id="ziyuancunchu" text="资源存仓库(不自动领取军报不用存)" />
                                <horizontal marginTop="6sp">
                                    <text text=" 保留前" textColor="#000000" textSize="14sp" />
                                    <input id="caijibaoliuHero" text="0" textSize="16sp" inputType="number" padding="8 6" />
                                    <text text="个英雄不参与采集，用来备战" textColor="#000000" textSize="14sp" />
                                </horizontal>
                                <horizontal marginTop="6sp">
                                    <text text=" 采集资源存量不少于" textColor="#000000" textSize="14sp" />
                                    <input id="cunliangNum" text="19000" textSize="16sp" inputType="number" padding="8 6" />
                                    <text text="的资源" textColor="#000000" textSize="14sp" />
                                </horizontal>
                                <horizontal marginTop="6sp">
                                    <text text=" 存量少于" textColor="#000000" textSize="14sp" />
                                    <input id="cunliangNumSy" text="0" textSize="16sp" inputType="number" padding="8 6" />
                                    <text text="自动撤回" textColor="#000000" textSize="14sp" />
                                </horizontal>
                                <horizontal>
                                    <text text=" 采集优先：" textColor="#000000" textSize="15sp" />
                                    <spinner id="caijiyouxian" entries="采集速度优先|采集负重优先" spinnerModer="dialog" />
                                </horizontal>
                            </vertical>
                            <text text="右下角“+”添加资源后请点击保存" textColor="#000000" textSize="12sp" marginTop="8sp" />
                            <horizontal>
                                <button w='45' textSize='10sp' id="ziyuanClean">清空</button>
                                {/* <button w='45' textSize='10sp' id="ok">粮↑</button>
                                <button w='45' textSize='10sp' id="ok">木↑</button>
                                <button w='45' textSize='10sp' id="ok">矿↑</button>
                                <button w='45' textSize='10sp' id="ok">等级</button> */}
                                <button w='45' textSize='10sp' id="zyDaochu">导出</button>
                                <button w='45' textSize='10sp' id="zyDaoru">导入</button>
                                <button w='50' style="Widget.AppCompat.Button.Colored" textSize='10sp' id="ziyuanSave">保存</button>
                            </horizontal>

                            {/* <ScrollView id="ziyuanScroll"> */}
                            <list id="ziyuanList" w='*' h='200sp'>
                                <horizontal>
                                    <button w='45' textSize='9sp' id="delete">删除</button>
                                    <text text="X:" textColor="#000000" textSize="14sp" marginLeft="6" />
                                    <text w='48' id="ziyuanX" textColor="#000000" text="{{this.x}}" textSize="16sp" gravity="center" padding="5 12" />
                                    {/* <input w='48' id="ziyuanX" text="{{this.x}}" textSize="16sp" inputType="number" disable={true} gravity="center" padding="5 12" /> */}
                                    <text text="Y:" textColor="#000000" textSize="14sp" />
                                    <text w='48' id="ziyuanY" textColor="#000000" text="{{this.y}}" textSize="16sp" gravity="center" padding="5 12" />
                                    {/* <input w='48' id="ziyuanY" text="{{this.y}}" textSize="16sp" inputType="number" disable={false} gravity="center" padding="5 12" /> */}

                                    <input w='25' text="{{this.level}}" textSize="16sp" inputType="number" padding="6 12" marginLeft="6" />
                                    <text text="级" textColor="#000000" textSize="14sp" />
                                    <text w='28' text="{{ziyuanGuolvFunc(this.type)}}" textColor="#000000" textSize="16sp" padding="6 12" marginLeft="6" />
                                </horizontal>
                            </list>
                            {/* </ScrollView> */}
                            <fab id="ziyuanAdd" w="auto" h="auto" src="@drawable/ic_add_black_48dp" margin="16" layout_gravity="bottom|right" tint="#ffffff" />
                        </vertical>
                    </frame>
                </ScrollView>
                {/* 战备设置 */}
                <frame>
                <vertical padding="10sp">
                    <vertical padding="8sp" marginTop="10sp" bg="#99FE01">
                        <horizontal >
                            <text text=" 是否开启：" textColor="#000000" textSize="15sp" />
                            <checkbox id="openDixi" text="敌袭策略" />
                        </horizontal>
                        <horizontal >
                            <checkbox id="dixiyuyin" text="敌袭语音提醒" />
                            <checkbox id="dixizhendong" text="敌袭震动提醒" />
                        </horizontal>
                        <vertical>
                            <checkbox id="dixiyoujian" text="敌袭邮件提醒" />
                            <input id="userrEmail" hint="请输入邮箱地址" text="" textSize="15sp" inputType="textEmailAddress" gravity="left" w="*" padding="8 6"/>
                        </vertical>
                    </vertical>
                    <vertical padding="8sp" marginTop="10sp" bg="#E43C2F">
                    <horizontal  >
                            <checkbox id="dixigaopinJc" text="敌袭高频检测(低性能手机,请勿使用)" />
                        </horizontal>
                        <horizontal  >
                            <checkbox id="fanjiduiwu" text="敌袭反击队伍" />
                            <checkbox id="fanjizhucheng" text="敌袭反击主城" />
                        </horizontal>
                        <horizontal  >
                            <checkbox id="zidongxiucheng" text="敌袭自动修城" />
                            <checkbox id="yuanbaoxiuchehng" text="敌袭元宝修城" />
                        </horizontal>
                        <horizontal >
                            <checkbox id="beidachehuicaiji" text="采集被打自动撤回" />
                        </horizontal>
                    </vertical>
                    </vertical>
                </frame>
                {/* 系统设置 */}
                <ScrollView>
                <frame>
                    <vertical padding="10sp">
                        <horizontal>
                            <text text="  激活码：" gravity="left" textColor={colorHei} textSize="15sp" />
                            <input id="jihuoma" hint="请输入注册码" text="" textSize="15sp" inputType="text" gravity="left" w="*" />
                        </horizontal>
                        <Switch id="autoService" text="无障碍服务" checked="{{auto.service != null}}" padding="8 8 8 8" textSize="15sp" />
                        <Switch id="floatyService" text="悬浮窗权限" checked="{{floaty.checkPermission()}}" padding="8 8 8 8" textSize="15sp" />
                        <vertical padding="10sp">
                            <text id="shebeiInfo" text=" 设备信息 " gravity="center" textSize="14sp" />
                        </vertical>
                        <vertical marginTop="10sp" padding="12sp" bg="#FFC801">
                                <horizontal>
                                    <checkbox id="logFile" text="日志文件" />
                                    <checkbox id="zhenjibaohuo" text="真机保活" />
                                </horizontal>
                            <horizontal>
                                <text text="  延迟速率：" textColor={colorHei} textSize="15sp" />
                                <input id="yanchisulv" hint="延迟速率" text="" textSize="15sp" inputType="text" gravity="center"/>
                                <text text=" (谨慎修改！)" textColor={colorHei} textSize="15sp" />
                            </horizontal>
                        </vertical>
                        <vertical >
                            <text text="欢迎使用道一科技系列产品" gravity="center" marginTop="8sp" textSize="15sp" />
                            <text autoLink="web" text="官网: http://Daoyikeji.com" gravity="center" />
                            <text text="抖/V: Daoyikeji88" gravity="center" />
                            <text id="appVersion" text=" 当前软件版本： " gravity="center" textSize="15sp" marginTop="6sp" />
                        </vertical>
                        <vertical>
                            <button style="Widget.AppCompat.Button.Colored" textSize='14sp' id="wangpan" marginTop="8sp">网盘下载密码:8888</button>

                            <button style="Widget.AppCompat.Button.Colored" textSize='14sp' id="cleanData" marginTop="10sp">清空所有数据</button>
                            <text text=" 真机保活功能保持真机不熄屏，请设置息屏时间在十分钟以上 " gravity="center" textSize="14sp" />
                        </vertical>
                    </vertical>

                    <list id="icons" >
                        <horizontal bg="?selectableItemBackground" w="*">
                            <img src="@drawable/{{this}}" h="30" margin="2" bg="?selectableItemBackgroundBorderless"/>
                            <text text="{{this}}" layout_gravity="center" textSize="10sp" textColor="black"/>
                        </horizontal>
                    </list>
                </frame>
                </ScrollView>
            </viewpager>
        </vertical>

        <vertical layout_gravity="left" bg="#ffffff" w="280">
            <img w="280" h="200" scaleType="fitXY" src="http://images.shejidaren.com/wp-content/uploads/2014/10/023746fki.jpg" />
            <list id="menu">
                <horizontal bg="?selectableItemBackground" w="*">
                    <img w="50" h="50" padding="16" src="{{this.icon}}" tint="{{colorHei}}" />
                    <text textColor="black" textSize="15sp" text="{{this.title}}" layout_gravity="center" />
                </horizontal>
            </list>
        </vertical>
    </drawer>
);

initJiemianFunc()
process.on('unhandledRejection', error => {
    log('处理异步函数警告', error.message);
});

function initJiemianFunc(){
    let str = "";
    str += "" + device.brand + " " + device.board + " " + device.model;
    str += "\n分辨率:" + device.width + " x " + device.height;
    // str += "\nbuildId:" + device.buildId;
    // str += "\n硬件名称:" + device.hardware;
    str += "\n安卓版本: " + device.release + " API: " + device.sdkInt;
    str += "\nAndroidId: " + device.getAndroidId();
    // str += "\n电量: " + device.getBattery();
    // str += "\n是否有虚拟导航: " + device.checkDeviceHasNavigationBar();
    // str += "\n虚拟导航高度: " + device.getVirtualBarHeigh();
    ui.shebeiInfo.text(" " + str + "     ");
    ui.appVersion.text(" 当前软件版本：" + appVersions + "     ");
    ui.toolbar.title = "世界模式 挂机辅助 " + appVersions;
    threads.start(function(){
    // 请求服务
    let reqs = http.postJson("http://123.60.43.199:8866/main/v1/auto/xysjNotice", {
        activationCode: storage.get("jihuoma", ""),
        aap: "yxsXysj",
        deviceWidth: device.width,
        deviceHeight: device.height,
        brand: device.brand,
        versionCode: project.versionCode,
        release: device.release,
        sdkInt: device.sdkInt,
        androidId: device.getAndroidId(),
        fingerprint: device.fingerprint,
        startTime: new Date().getTime()
    });
    let rJson = reqs.body.json();
        if (rJson.code == 200) {
            ui.gonggaoa.text(" " + rJson.data + "     ");
        }else {
            toastLog(rJson.data)
            ui.finish()
        }
    })
}

// 数据转化
function ziyuanGuolvFunc(params) {
    let a = '粮'
    if (params == '1') {
        a = '粮'
    }
    if (params == '2') {
        a = '木'
    }
    if (params == '3') {
        a = '矿'
    }
    return a
}

// 设置数据源
ui.ziyuanList.setDataSource(toCaijiList);
// 添加
ui.ziyuanAdd.on("click", function () {
    dialogs.rawInput("资源信息(X,Y,等级)", "88,66,5")
        .then(title => {
            let arr = title.split(',')
            if (!title || arr.length != 3) {
                log("资源格式不正确")
                return;
            }
            dialogs.select("请选择资源类型", ["粮田", "木头", "铁矿"])
                .then(i => {
                    toCaijiList.push({
                        x: arr[0],
                        y: arr[1],
                        level: arr[2],
                        type: i + 1
                    });
                    log("添加资源", toCaijiList)
                });
        })
})
// 清空
ui.ziyuanClean.on("click", function () {
    toCaijiList.splice(0, toCaijiList.length);
    toastLog('清空资源配置')
})
ui.zyDaochu.on("click", function () {
    log("资源", toCaijiList)
    let copyList = ''
    for (let index = 0; index < toCaijiList.length; index++) {
        let element = toCaijiList[index];
        copyList += element.x+","+element.y+","+element.level+","+element.type+'\n'
    }
    log("copyList", copyList)
    setClip(copyList);
    toastLog('已复制')
})
ui.zyDaoru.on("click", function () {
    let getClipSs = getClip()
    getClipSs = getClipSs.split('\n')
    log(getClipSs);
    for (let index = 0; index < getClipSs.length; index++) {
        let element = getClipSs[index];
        element = element.split(',')
        if (element.length > 2) {
            let level = element[2]
            let type = element[3]
            if (!level) {
                level = 1
            }else{
                level = level.replace(/\D/g, "");
                log('处理level', level);
            }
            if (!type) {
                type = 1
            }else{
                type = type.replace(/\D/g, "");
                log('处理type', type);
            }
            toCaijiList.push({ x: element[0], y: element[1], level: level, type: type })
        }
    }
    log(toCaijiList);
    storage.put("caijiItems", toCaijiList);
    toastLog('已导入并保存')
})
// 保存
ui.ziyuanSave.on("click", function () {
    log("保存资源", toCaijiList)
    storage.put("caijiItems", toCaijiList);
    toastLog('配置已保存')
})

// 删除
ui.ziyuanList.on('item_bind', (itemView, itemHolder) => {
    //删除数据 
    itemView.delete.on('click', () => {
        log(itemHolder.position, toCaijiList)
        toCaijiList.splice(itemHolder.position, 1);
    });
});

// 网盘更新
ui.wangpan.on("click", function () {
    app.openUrl('https://stack.lanzouh.com/b013wfexe')
})

ui.cleanData.on("click", function () {
    storages.remove('autotouchShijieXy')
    toastLog('数据已清空，请关闭app重新打开配置')
})

// 无障碍权限
ui.autoService.on("check", function (checked) {
    if (checked && auto.service == null) {
        app.startActivity({
            action: "android.settings.ACCESSIBILITY_SETTINGS"
        });
    }
    if (!checked && auto.service != null) {
        auto.service.disableSelf();
    }
});
// 悬浮窗权限
ui.floatyService.on("check", function (checked) {
    if (!floaty.checkPermission()) {
        // 没有悬浮窗权限，提示用户并跳转请求
        toastLog("请开启悬浮窗权限来显示悬浮窗，请在随后的界面中允许并重新运行本脚本。");
        floaty.requestPermission();
        return;
    } else {
        log('已获取悬浮窗权限');
    }
});


//创建选项菜单(右上角)
ui.emitter.on("create_options_menu", menu => {
    menu.add("保存");
    menu.add("运行");
});
//监听选项菜单点击
ui.emitter.on("options_item_selected", (e, item) => {
    e.consumed = true;
    switch (item.getTitle()) {
        case "保存":
            saveconfig();
            toastLog("1配置已保存");
            break;
        case "运行":
            // 保存配置
            saveconfig()
            //程序开始运行之前判断无障碍服务
            if (auto.service == null) {
                toastLog("请先开启无障碍服务！");
                app.startActivity({
                    action: "android.settings.ACCESSIBILITY_SETTINGS"
                });
                return;
            } else {
                log('已获取无障碍权限');
            }
            // 悬浮窗权限
            if (!runagain) {
                if (!floaty.checkPermission()) {
                    // 没有悬浮窗权限，提示用户并跳转请求
                    toastLog("请开启悬浮窗权限来显示悬浮窗，请在随后的界面中允许并重新运行本脚本。");
                    floaty.requestPermission();
                    return;
                } else {
                    log('已获取悬浮窗权限');
                }
            }
            // 激活码
            if (storage.get("jihuoma", "").length != 28) {
                toastLog("激活码错误，请打开系统设置选项验证激活码！");
                return;
            }
            // 设备信息   
            deviceJizhunFunc();
            // 右上悬浮窗
            xuanfuFunc()
            // 输出日志窗口
            xuanfuLogFunc()
            myLogFunc('分辨率：'+deviceWidth+'*'+deviceHeight)
            myLogFunc('分辨率基准：'+picJizhun)
            // 线程定时器
            if (Boolean(storage.get("islingdidenglu", false))) {
                timeThreads = threads.start(function(){
                    log('定时器')
                    let threadImgs = images.read("./res/重连.png");
                        threadImgs = images.scale(threadImgs, picJizhun, picJizhunHeight);
                    let jin = true;
                    setInterval(function(){
                        log("当前线程(子线程):" + threads.currentThread());
                        let threadP = findImage(captureScreen(), threadImgs);
                        if (threadP && jin) {
                            jin = false;
                            caijiduiwu = 0;
                            myLogStr = "";
                            floatyConsole.close()
                            log('停止')
                            if (myThreads) {
                                myThreads.interrupt();
                            }
                            myThreads = null;
                            let timess = Number(storage.get("lingdidenglu", "20"))
                            let timeout = setTimeout(() => {
                                log('重连')
                                click(threadP.x, threadP.y)
                                sleep(yanchi5)
                                // 输出日志窗口
                                xuanfuLogFunc()
                                clearTimeout(timeout) 
                                // 重新运行
                                mainFunc()
                                
                            }, timess*60*1000);
                        }
                    }, 10000);

                });
            }
            // 启动流程
            mainFunc(true);
            log('runing...')
            break;
    }
});
activity.setSupportActionBar(ui.toolbar);

//设置滑动页面的标题
ui.viewpager.setTitles(["功能设置", "采集设置", "备战设置", "系统设置"]);
//让滑动页面和标签栏联动
ui.tabs.setupWithViewPager(ui.viewpager);
var icons = ['ic_3d_rotation_black_48dp', 'ic_accessibility_black_48dp', 'ic_accessible_black_48dp', 'ic_account_balance_black_48dp', 'ic_account_balance_wallet_black_48dp', 'ic_account_box_black_48dp', 'ic_account_circle_black_48dp', 'ic_add_shopping_cart_black_48dp', 'ic_alarm_add_black_48dp', 'ic_alarm_black_48dp', 'ic_alarm_off_black_48dp', 'ic_alarm_on_black_48dp', 'ic_all_out_black_48dp', 'ic_android_black_48dp', 'ic_announcement_black_48dp', 'ic_aspect_ratio_black_48dp', 'ic_assessment_black_48dp', 'ic_assignment_black_48dp', 'ic_assignment_ind_black_48dp', 'ic_assignment_late_black_48dp', 'ic_assignment_returned_black_48dp', 'ic_assignment_return_black_48dp', 'ic_assignment_turned_in_black_48dp', 'ic_autorenew_black_48dp', 'ic_backup_black_48dp', 'ic_bookmark_black_48dp', 'ic_bookmark_border_black_48dp', 'ic_book_black_48dp', 'ic_bug_report_black_48dp', 'ic_build_black_48dp', 'ic_cached_black_48dp', 'ic_camera_enhance_black_48dp', 'ic_card_giftcard_black_48dp', 'ic_card_membership_black_48dp', 'ic_card_travel_black_48dp', 'ic_change_history_black_48dp', 'ic_check_circle_black_48dp', 'ic_chrome_reader_mode_black_48dp', 'ic_class_black_48dp', 'ic_code_black_48dp', 'ic_compare_arrows_black_48dp', 'ic_copyright_black_48dp', 'ic_credit_card_black_48dp', 'ic_dashboard_black_48dp', 'ic_date_range_black_48dp', 'ic_delete_black_48dp', 'ic_delete_forever_black_48dp', 'ic_description_black_48dp', 'ic_dns_black_48dp', 'ic_done_all_black_48dp', 'ic_done_black_48dp', 'ic_donut_large_black_48dp', 'ic_donut_small_black_48dp', 'ic_eject_black_48dp', 'ic_euro_symbol_black_48dp', 'ic_event_black_48dp', 'ic_event_seat_black_48dp', 'ic_exit_to_app_black_48dp', 'ic_explore_black_48dp', 'ic_extension_black_48dp', 'ic_face_black_48dp', 'ic_favorite_black_48dp', 'ic_favorite_border_black_48dp', 'ic_feedback_black_48dp', 'ic_find_in_page_black_48dp', 'ic_find_replace_black_48dp', 'ic_fingerprint_black_48dp', 'ic_flight_land_black_48dp', 'ic_flight_takeoff_black_48dp', 'ic_flip_to_back_black_48dp', 'ic_flip_to_front_black_48dp', 'ic_gavel_black_48dp', 'ic_get_app_black_48dp', 'ic_gif_black_48dp', 'ic_grade_black_48dp', 'ic_group_work_black_48dp', 'ic_g_translate_black_48dp', 'ic_help_black_48dp', 'ic_help_outline_black_48dp', 'ic_highlight_off_black_48dp', 'ic_history_black_48dp', 'ic_home_black_48dp', 'ic_hourglass_empty_black_48dp', 'ic_hourglass_full_black_48dp', 'ic_https_black_48dp', 'ic_http_black_48dp', 'ic_important_devices_black_48dp', 'ic_info_black_48dp', 'ic_info_outline_black_48dp', 'ic_input_black_48dp', 'ic_invert_colors_black_48dp', 'ic_label_black_48dp', 'ic_label_outline_black_48dp', 'ic_language_black_48dp', 'ic_launch_black_48dp', 'ic_lightbulb_outline_black_48dp', 'ic_line_style_black_48dp', 'ic_line_weight_black_48dp', 'ic_list_black_48dp', 'ic_lock_black_48dp', 'ic_lock_open_black_48dp', 'ic_lock_outline_black_48dp', 'ic_loyalty_black_48dp', 'ic_markunread_mailbox_black_48dp', 'ic_motorcycle_black_48dp', 'ic_note_add_black_48dp', 'ic_offline_pin_black_48dp', 'ic_opacity_black_48dp', 'ic_open_in_browser_black_48dp', 'ic_open_in_new_black_48dp', 'ic_open_with_black_48dp', 'ic_pageview_black_48dp', 'ic_pan_tool_black_48dp', 'ic_payment_black_48dp', 'ic_perm_camera_mic_black_48dp', 'ic_perm_contact_calendar_black_48dp', 'ic_perm_data_setting_black_48dp', 'ic_perm_device_information_black_48dp', 'ic_perm_identity_black_48dp', 'ic_perm_media_black_48dp', 'ic_perm_phone_msg_black_48dp', 'ic_perm_scan_wifi_black_48dp', 'ic_pets_black_48dp', 'ic_picture_in_picture_alt_black_48dp', 'ic_picture_in_picture_black_48dp', 'ic_play_for_work_black_48dp', 'ic_polymer_black_48dp', 'ic_power_settings_new_black_48dp', 'ic_pregnant_woman_black_48dp', 'ic_print_black_48dp', 'ic_query_builder_black_48dp', 'ic_question_answer_black_48dp', 'ic_receipt_black_48dp', 'ic_record_voice_over_black_48dp', 'ic_redeem_black_48dp', 'ic_remove_shopping_cart_black_48dp', 'ic_reorder_black_48dp', 'ic_report_problem_black_48dp', 'ic_restore_black_48dp', 'ic_restore_page_black_48dp', 'ic_room_black_48dp', 'ic_rounded_corner_black_48dp', 'ic_rowing_black_48dp', 'ic_schedule_black_48dp', 'ic_search_black_48dp', 'ic_settings_applications_black_48dp', 'ic_settings_backup_restore_black_48dp', 'ic_settings_black_48dp', 'ic_settings_bluetooth_black_48dp', 'ic_settings_brightness_black_48dp', 'ic_settings_cell_black_48dp', 'ic_settings_ethernet_black_48dp', 'ic_settings_input_antenna_black_48dp', 'ic_settings_input_component_black_48dp', 'ic_settings_input_composite_black_48dp', 'ic_settings_input_hdmi_black_48dp', 'ic_settings_input_svideo_black_48dp', 'ic_settings_overscan_black_48dp', 'ic_settings_phone_black_48dp', 'ic_settings_power_black_48dp', 'ic_settings_remote_black_48dp', 'ic_settings_voice_black_48dp', 'ic_shopping_basket_black_48dp', 'ic_shopping_cart_black_48dp', 'ic_shop_black_48dp', 'ic_shop_two_black_48dp', 'ic_speaker_notes_black_48dp', 'ic_speaker_notes_off_black_48dp', 'ic_spellcheck_black_48dp', 'ic_stars_black_48dp', 'ic_store_black_48dp', 'ic_subject_black_48dp', 'ic_supervisor_account_black_48dp', 'ic_swap_horiz_black_48dp', 'ic_swap_vertical_circle_black_48dp', 'ic_swap_vert_black_48dp', 'ic_system_update_alt_black_48dp', 'ic_tab_black_48dp', 'ic_tab_unselected_black_48dp', 'ic_theaters_black_48dp', 'ic_thumbs_up_down_black_48dp', 'ic_thumb_down_black_48dp', 'ic_thumb_up_black_48dp', 'ic_timeline_black_48dp', 'ic_toc_black_48dp', 'ic_today_black_48dp', 'ic_toll_black_48dp', 'ic_touch_app_black_48dp', 'ic_track_changes_black_48dp', 'ic_translate_black_48dp', 'ic_trending_down_black_48dp', 'ic_trending_flat_black_48dp', 'ic_trending_up_black_48dp', 'ic_turned_in_black_48dp', 'ic_turned_in_not_black_48dp', 'ic_update_black_48dp', 'ic_verified_user_black_48dp', 'ic_view_agenda_black_48dp', 'ic_view_array_black_48dp', 'ic_view_carousel_black_48dp', 'ic_view_column_black_48dp', 'ic_view_day_black_48dp', 'ic_view_headline_black_48dp', 'ic_view_list_black_48dp', 'ic_view_module_black_48dp', 'ic_view_quilt_black_48dp', 'ic_view_stream_black_48dp', 'ic_view_week_black_48dp', 'ic_visibility_black_48dp', 'ic_visibility_off_black_48dp', 'ic_watch_later_black_48dp', 'ic_work_black_48dp', 'ic_youtube_searched_for_black_48dp', 'ic_zoom_in_black_48dp', 'ic_zoom_out_black_48dp', 'ic_add_alert_black_48dp', 'ic_error_black_48dp', 'ic_error_outline_black_48dp', 'ic_warning_black_48dp', 'ic_add_to_queue_black_48dp', 'ic_airplay_black_48dp', 'ic_album_black_48dp', 'ic_art_track_black_48dp', 'ic_av_timer_black_48dp', 'ic_branding_watermark_black_48dp', 'ic_call_to_action_black_48dp', 'ic_closed_caption_black_48dp', 'ic_equalizer_black_48dp', 'ic_explicit_black_48dp', 'ic_fast_forward_black_48dp', 'ic_fast_rewind_black_48dp', 'ic_featured_play_list_black_48dp', 'ic_featured_video_black_48dp', 'ic_fiber_dvr_black_48dp', 'ic_fiber_manual_record_black_48dp', 'ic_fiber_new_black_48dp', 'ic_fiber_pin_black_48dp', 'ic_fiber_smart_record_black_48dp', 'ic_forward_10_black_48dp', 'ic_forward_30_black_48dp', 'ic_forward_5_black_48dp', 'ic_games_black_48dp', 'ic_hd_black_48dp', 'ic_hearing_black_48dp', 'ic_high_quality_black_48dp', 'ic_library_add_black_48dp', 'ic_library_books_black_48dp', 'ic_library_music_black_48dp', 'ic_loop_black_48dp', 'ic_mic_black_48dp', 'ic_mic_none_black_48dp', 'ic_mic_off_black_48dp', 'ic_movie_black_48dp', 'ic_music_video_black_48dp', 'ic_new_releases_black_48dp', 'ic_note_black_48dp', 'ic_not_interested_black_48dp', 'ic_pause_black_48dp', 'ic_pause_circle_filled_black_48dp', 'ic_pause_circle_outline_black_48dp', 'ic_playlist_add_black_48dp', 'ic_playlist_add_check_black_48dp', 'ic_playlist_play_black_48dp', 'ic_play_arrow_black_48dp', 'ic_play_circle_filled_black_48dp', 'ic_play_circle_filled_white_black_48dp', 'ic_play_circle_outline_black_48dp', 'ic_queue_black_48dp', 'ic_queue_music_black_48dp', 'ic_queue_play_next_black_48dp', 'ic_radio_black_48dp', 'ic_recent_actors_black_48dp', 'ic_remove_from_queue_black_48dp', 'ic_repeat_black_48dp', 'ic_repeat_one_black_48dp', 'ic_replay_10_black_48dp', 'ic_replay_30_black_48dp', 'ic_replay_5_black_48dp', 'ic_replay_black_48dp', 'ic_shuffle_black_48dp', 'ic_skip_next_black_48dp', 'ic_skip_previous_black_48dp', 'ic_slow_motion_video_black_48dp', 'ic_snooze_black_48dp', 'ic_sort_by_alpha_black_48dp', 'ic_stop_black_48dp', 'ic_subscriptions_black_48dp', 'ic_subtitles_black_48dp', 'ic_surround_sound_black_48dp', 'ic_videocam_black_48dp', 'ic_videocam_off_black_48dp', 'ic_video_call_black_48dp', 'ic_video_label_black_48dp', 'ic_video_library_black_48dp', 'ic_volume_down_black_48dp', 'ic_volume_mute_black_48dp', 'ic_volume_off_black_48dp', 'ic_volume_up_black_48dp', 'ic_web_asset_black_48dp', 'ic_web_black_48dp', 'ic_business_black_48dp', 'ic_call_black_48dp', 'ic_call_end_black_48dp', 'ic_call_made_black_48dp', 'ic_call_merge_black_48dp', 'ic_call_missed_black_48dp', 'ic_call_missed_outgoing_black_48dp', 'ic_call_received_black_48dp', 'ic_call_split_black_48dp', 'ic_chat_black_48dp', 'ic_chat_bubble_black_48dp', 'ic_chat_bubble_outline_black_48dp', 'ic_clear_all_black_48dp', 'ic_comment_black_48dp', 'ic_contacts_black_48dp', 'ic_contact_mail_black_48dp', 'ic_contact_phone_black_48dp', 'ic_dialer_sip_black_48dp', 'ic_dialpad_black_48dp', 'ic_email_black_48dp', 'ic_forum_black_48dp', 'ic_import_contacts_black_48dp', 'ic_import_export_black_48dp', 'ic_invert_colors_off_black_48dp', 'ic_live_help_black_48dp', 'ic_location_off_black_48dp', 'ic_location_on_black_48dp', 'ic_mail_outline_black_48dp', 'ic_message_black_48dp', 'ic_no_sim_black_48dp', 'ic_phonelink_erase_black_48dp', 'ic_phonelink_lock_black_48dp', 'ic_phonelink_ring_black_48dp', 'ic_phonelink_setup_black_48dp', 'ic_phone_black_48dp', 'ic_portable_wifi_off_black_48dp', 'ic_present_to_all_black_48dp', 'ic_ring_volume_black_48dp', 'ic_rss_feed_black_48dp', 'ic_screen_share_black_48dp', 'ic_speaker_phone_black_48dp', 'ic_stay_current_landscape_black_48dp', 'ic_stay_current_portrait_black_48dp', 'ic_stay_primary_landscape_black_48dp',
 'ic_stay_primary_portrait_black_48dp', 'ic_stop_screen_share_black_48dp', 'ic_swap_calls_black_48dp', 'ic_textsms_black_48dp', 'ic_voicemail_black_48dp', 'ic_vpn_key_black_48dp', 'ic_add_black_48dp', 'ic_add_box_black_48dp', 'ic_add_circle_black_48dp', 'ic_add_circle_outline_black_48dp', 'ic_archive_black_48dp', 'ic_backspace_black_48dp', 'ic_block_black_48dp', 'ic_clear_black_48dp', 'ic_content_copy_black_48dp', 'ic_content_cut_black_48dp', 'ic_content_paste_black_48dp', 'ic_create_black_48dp', 'ic_delete_sweep_black_48dp', 'ic_drafts_black_48dp', 'ic_filter_list_black_48dp', 'ic_flag_black_48dp', 'ic_font_download_black_48dp', 'ic_forward_black_48dp', 'ic_gesture_black_48dp', 'ic_inbox_black_48dp', 'ic_link_black_48dp', 'ic_low_priority_black_48dp', 'ic_mail_black_48dp', 'ic_markunread_black_48dp', 'ic_move_to_inbox_black_48dp', 'ic_next_week_black_48dp', 'ic_redo_black_48dp', 'ic_remove_black_48dp', 'ic_remove_circle_black_48dp', 'ic_remove_circle_outline_black_48dp', 'ic_reply_all_black_48dp', 'ic_reply_black_48dp', 'ic_report_black_48dp', 'ic_save_black_48dp', 'ic_select_all_black_48dp', 'ic_send_black_48dp', 'ic_sort_black_48dp', 'ic_text_format_black_48dp', 'ic_unarchive_black_48dp', 'ic_undo_black_48dp', 'ic_weekend_black_48dp', 'ic_access_alarms_black_48dp', 'ic_access_alarm_black_48dp', 'ic_access_time_black_48dp', 'ic_add_alarm_black_48dp', 'ic_airplanemode_active_black_48dp', 'ic_airplanemode_inactive_black_48dp', 'ic_battery_20_black_48dp', 'ic_battery_30_black_48dp', 'ic_battery_50_black_48dp', 'ic_battery_60_black_48dp', 'ic_battery_80_black_48dp', 'ic_battery_90_black_48dp', 'ic_battery_alert_black_48dp', 'ic_battery_charging_20_black_48dp', 'ic_battery_charging_30_black_48dp', 'ic_battery_charging_50_black_48dp', 'ic_battery_charging_60_black_48dp', 'ic_battery_charging_80_black_48dp', 'ic_battery_charging_90_black_48dp', 'ic_battery_charging_full_black_48dp', 'ic_battery_full_black_48dp', 'ic_battery_std_black_48dp', 'ic_battery_unknown_black_48dp', 'ic_bluetooth_black_48dp', 'ic_bluetooth_connected_black_48dp', 'ic_bluetooth_disabled_black_48dp', 'ic_bluetooth_searching_black_48dp', 'ic_brightness_auto_black_48dp', 'ic_brightness_high_black_48dp', 'ic_brightness_low_black_48dp', 'ic_brightness_medium_black_48dp', 'ic_data_usage_black_48dp', 'ic_developer_mode_black_48dp', 'ic_devices_black_48dp', 'ic_dvr_black_48dp', 'ic_gps_fixed_black_48dp', 'ic_gps_not_fixed_black_48dp', 'ic_gps_off_black_48dp', 'ic_graphic_eq_black_48dp', 'ic_location_disabled_black_48dp', 'ic_location_searching_black_48dp', 'ic_network_cell_black_48dp', 'ic_network_wifi_black_48dp', 'ic_nfc_black_48dp', 'ic_screen_lock_landscape_black_48dp', 'ic_screen_lock_portrait_black_48dp', 'ic_screen_lock_rotation_black_48dp', 'ic_screen_rotation_black_48dp', 'ic_sd_storage_black_48dp', 'ic_settings_system_daydream_black_48dp', 'ic_signal_cellular_0_bar_black_48dp', 'ic_signal_cellular_1_bar_black_48dp', 'ic_signal_cellular_2_bar_black_48dp', 'ic_signal_cellular_3_bar_black_48dp', 'ic_signal_cellular_4_bar_black_48dp', 'ic_signal_cellular_connected_no_internet_0_bar_black_48dp', 'ic_signal_cellular_connected_no_internet_1_bar_black_48dp', 'ic_signal_cellular_connected_no_internet_2_bar_black_48dp', 'ic_signal_cellular_connected_no_internet_3_bar_black_48dp', 'ic_signal_cellular_connected_no_internet_4_bar_black_48dp', 'ic_signal_cellular_no_sim_black_48dp', 'ic_signal_cellular_null_black_48dp', 'ic_signal_cellular_off_black_48dp', 'ic_signal_wifi_0_bar_black_48dp', 'ic_signal_wifi_1_bar_black_48dp', 'ic_signal_wifi_1_bar_lock_black_48dp', 'ic_signal_wifi_2_bar_black_48dp', 'ic_signal_wifi_2_bar_lock_black_48dp', 'ic_signal_wifi_3_bar_black_48dp', 'ic_signal_wifi_3_bar_lock_black_48dp', 'ic_signal_wifi_4_bar_black_48dp', 'ic_signal_wifi_4_bar_lock_black_48dp', 'ic_signal_wifi_off_black_48dp', 'ic_storage_black_48dp', 'ic_usb_black_48dp', 'ic_wallpaper_black_48dp', 'ic_widgets_black_48dp', 'ic_wifi_lock_black_48dp', 'ic_wifi_tethering_black_48dp', 'ic_attach_file_black_48dp', 'ic_attach_money_black_48dp', 'ic_border_all_black_48dp', 'ic_border_bottom_black_48dp', 'ic_border_clear_black_48dp', 'ic_border_color_black_48dp', 'ic_border_horizontal_black_48dp', 'ic_border_inner_black_48dp', 'ic_border_left_black_48dp', 'ic_border_outer_black_48dp', 'ic_border_right_black_48dp', 'ic_border_style_black_48dp', 'ic_border_top_black_48dp', 'ic_border_vertical_black_48dp', 'ic_bubble_chart_black_48dp', 'ic_drag_handle_black_48dp', 'ic_format_align_center_black_48dp', 'ic_format_align_justify_black_48dp', 'ic_format_align_left_black_48dp', 'ic_format_align_right_black_48dp', 'ic_format_bold_black_48dp', 'ic_format_clear_black_48dp', 'ic_format_color_fill_black_48dp', 'ic_format_color_reset_black_48dp', 'ic_format_color_text_black_48dp', 'ic_format_indent_decrease_black_48dp', 'ic_format_indent_increase_black_48dp', 'ic_format_italic_black_48dp', 'ic_format_line_spacing_black_48dp', 'ic_format_list_bulleted_black_48dp', 'ic_format_list_numbered_black_48dp', 'ic_format_paint_black_48dp', 'ic_format_quote_black_48dp', 'ic_format_shapes_black_48dp', 'ic_format_size_black_48dp', 'ic_format_strikethrough_black_48dp', 'ic_format_textdirection_l_to_r_black_48dp', 'ic_format_textdirection_r_to_l_black_48dp', 'ic_format_underlined_black_48dp', 'ic_functions_black_48dp', 'ic_highlight_black_48dp', 'ic_insert_chart_black_48dp', 'ic_insert_comment_black_48dp', 'ic_insert_drive_file_black_48dp', 'ic_insert_emoticon_black_48dp', 'ic_insert_invitation_black_48dp', 'ic_insert_link_black_48dp', 'ic_insert_photo_black_48dp', 'ic_linear_scale_black_48dp', 'ic_merge_type_black_48dp', 'ic_mode_comment_black_48dp', 'ic_mode_edit_black_48dp', 'ic_monetization_on_black_48dp', 'ic_money_off_black_48dp', 'ic_multiline_chart_black_48dp', 'ic_pie_chart_black_48dp', 'ic_pie_chart_outlined_black_48dp', 'ic_publish_black_48dp', 'ic_short_text_black_48dp', 'ic_show_chart_black_48dp', 'ic_space_bar_black_48dp', 'ic_strikethrough_s_black_48dp', 'ic_text_fields_black_48dp', 'ic_title_black_48dp', 'ic_vertical_align_bottom_black_48dp', 'ic_vertical_align_center_black_48dp', 'ic_vertical_align_top_black_48dp', 'ic_wrap_text_black_48dp', 'ic_attachment_black_48dp', 'ic_cloud_black_48dp', 'ic_cloud_circle_black_48dp', 'ic_cloud_done_black_48dp', 'ic_cloud_download_black_48dp', 'ic_cloud_off_black_48dp', 'ic_cloud_queue_black_48dp', 'ic_cloud_upload_black_48dp', 'ic_create_new_folder_black_48dp', 'ic_file_download_black_48dp', 'ic_file_upload_black_48dp', 'ic_folder_black_48dp', 'ic_folder_open_black_48dp', 'ic_folder_shared_black_48dp', 'ic_cast_black_48dp', 'ic_cast_connected_black_48dp', 'ic_computer_black_48dp', 'ic_desktop_mac_black_48dp', 'ic_desktop_windows_black_48dp', 'ic_developer_board_black_48dp', 'ic_devices_other_black_48dp', 'ic_device_hub_black_48dp', 'ic_dock_black_48dp', 'ic_gamepad_black_48dp', 'ic_headset_black_48dp', 'ic_headset_mic_black_48dp', 'ic_keyboard_arrow_down_black_48dp', 'ic_keyboard_arrow_left_black_48dp', 'ic_keyboard_arrow_right_black_48dp', 'ic_keyboard_arrow_up_black_48dp', 'ic_keyboard_backspace_black_48dp', 'ic_keyboard_black_48dp', 'ic_keyboard_capslock_black_48dp', 'ic_keyboard_hide_black_48dp', 'ic_keyboard_return_black_48dp', 'ic_keyboard_tab_black_48dp', 'ic_keyboard_voice_black_48dp', 'ic_laptop_black_48dp', 'ic_laptop_chromebook_black_48dp', 'ic_laptop_mac_black_48dp', 'ic_laptop_windows_black_48dp', 'ic_memory_black_48dp', 'ic_mouse_black_48dp', 'ic_phonelink_black_48dp', 'ic_phonelink_off_black_48dp', 'ic_phone_android_black_48dp', 'ic_phone_iphone_black_48dp', 'ic_power_input_black_48dp', 'ic_router_black_48dp', 'ic_scanner_black_48dp', 'ic_security_black_48dp', 'ic_sim_card_black_48dp', 'ic_smartphone_black_48dp', 'ic_speaker_black_48dp', 'ic_speaker_group_black_48dp', 'ic_tablet_android_black_48dp', 'ic_tablet_black_48dp', 'ic_tablet_mac_black_48dp', 'ic_toys_black_48dp', 'ic_tv_black_48dp', 'ic_videogame_asset_black_48dp', 'ic_watch_black_48dp', 'ic_add_a_photo_black_48dp', 'ic_add_to_photos_black_48dp', 'ic_adjust_black_48dp', 'ic_assistant_black_48dp', 'ic_assistant_photo_black_48dp', 'ic_audiotrack_black_48dp', 'ic_blur_circular_black_48dp', 'ic_blur_linear_black_48dp', 'ic_blur_off_black_48dp', 'ic_blur_on_black_48dp', 'ic_brightness_1_black_48dp', 'ic_brightness_2_black_48dp', 'ic_brightness_3_black_48dp', 'ic_brightness_4_black_48dp', 'ic_brightness_5_black_48dp', 'ic_brightness_6_black_48dp', 'ic_brightness_7_black_48dp', 'ic_broken_image_black_48dp', 'ic_brush_black_48dp', 'ic_burst_mode_black_48dp', 'ic_camera_alt_black_48dp', 'ic_camera_black_48dp', 'ic_camera_front_black_48dp', 'ic_camera_rear_black_48dp', 'ic_camera_roll_black_48dp', 'ic_center_focus_strong_black_48dp', 'ic_center_focus_weak_black_48dp', 'ic_collections_black_48dp', 'ic_collections_bookmark_black_48dp', 'ic_colorize_black_48dp', 'ic_color_lens_black_48dp', 'ic_compare_black_48dp', 'ic_control_point_black_48dp', 'ic_control_point_duplicate_black_48dp', 'ic_crop_16_9_black_48dp', 'ic_crop_3_2_black_48dp', 'ic_crop_5_4_black_48dp', 'ic_crop_7_5_black_48dp', 'ic_crop_black_48dp', 'ic_crop_din_black_48dp', 'ic_crop_free_black_48dp', 'ic_crop_landscape_black_48dp', 'ic_crop_original_black_48dp', 'ic_crop_portrait_black_48dp', 'ic_crop_rotate_black_48dp', 'ic_crop_square_black_48dp', 'ic_dehaze_black_48dp', 'ic_details_black_48dp', 'ic_edit_black_48dp', 'ic_exposure_black_48dp', 'ic_exposure_neg_1_black_48dp', 'ic_exposure_neg_2_black_48dp', 'ic_exposure_plus_1_black_48dp', 'ic_exposure_plus_2_black_48dp', 'ic_exposure_zero_black_48dp', 'ic_filter_1_black_48dp', 'ic_filter_2_black_48dp', 'ic_filter_3_black_48dp', 'ic_filter_4_black_48dp', 'ic_filter_5_black_48dp', 'ic_filter_6_black_48dp', 'ic_filter_7_black_48dp', 'ic_filter_8_black_48dp', 'ic_filter_9_black_48dp', 'ic_filter_9_plus_black_48dp', 'ic_filter_black_48dp', 'ic_filter_b_and_w_black_48dp', 'ic_filter_center_focus_black_48dp', 'ic_filter_drama_black_48dp', 'ic_filter_frames_black_48dp', 
 'ic_filter_hdr_black_48dp', 'ic_filter_none_black_48dp', 'ic_filter_tilt_shift_black_48dp', 'ic_filter_vintage_black_48dp', 'ic_flare_black_48dp', 'ic_flash_auto_black_48dp', 'ic_flash_off_black_48dp', 'ic_flash_on_black_48dp', 'ic_flip_black_48dp', 'ic_gradient_black_48dp', 'ic_grain_black_48dp', 'ic_grid_off_black_48dp', 'ic_grid_on_black_48dp', 'ic_hdr_off_black_48dp', 'ic_hdr_on_black_48dp', 'ic_hdr_strong_black_48dp', 'ic_hdr_weak_black_48dp', 'ic_healing_black_48dp', 'ic_image_aspect_ratio_black_48dp', 'ic_image_black_48dp', 'ic_iso_black_48dp', 'ic_landscape_black_48dp', 'ic_leak_add_black_48dp', 'ic_leak_remove_black_48dp', 'ic_lens_black_48dp', 'ic_linked_camera_black_48dp', 'ic_looks_3_black_48dp', 'ic_looks_4_black_48dp', 'ic_looks_5_black_48dp', 'ic_looks_6_black_48dp', 'ic_looks_black_48dp', 'ic_looks_one_black_48dp', 'ic_looks_two_black_48dp', 'ic_loupe_black_48dp', 'ic_monochrome_photos_black_48dp', 'ic_movie_creation_black_48dp', 'ic_movie_filter_black_48dp', 'ic_music_note_black_48dp', 'ic_nature_black_48dp', 'ic_nature_people_black_48dp', 'ic_navigate_before_black_48dp', 'ic_navigate_next_black_48dp', 'ic_palette_black_48dp', 'ic_panorama_black_48dp', 'ic_panorama_fish_eye_black_48dp', 'ic_panorama_horizontal_black_48dp', 'ic_panorama_vertical_black_48dp', 'ic_panorama_wide_angle_black_48dp', 'ic_photo_album_black_48dp', 'ic_photo_black_48dp', 'ic_photo_camera_black_48dp', 'ic_photo_filter_black_48dp', 'ic_photo_library_black_48dp', 'ic_photo_size_select_actual_black_48dp', 'ic_photo_size_select_large_black_48dp', 'ic_photo_size_select_small_black_48dp', 'ic_picture_as_pdf_black_48dp', 'ic_portrait_black_48dp', 'ic_remove_red_eye_black_48dp', 'ic_rotate_90_degrees_ccw_black_48dp', 'ic_rotate_left_black_48dp', 'ic_rotate_right_black_48dp', 'ic_slideshow_black_48dp', 'ic_straighten_black_48dp', 'ic_style_black_48dp', 'ic_switch_camera_black_48dp', 'ic_switch_video_black_48dp', 'ic_tag_faces_black_48dp', 'ic_texture_black_48dp', 'ic_timelapse_black_48dp', 'ic_timer_10_black_48dp', 'ic_timer_3_black_48dp', 'ic_timer_black_48dp', 'ic_timer_off_black_48dp', 'ic_tonality_black_48dp', 'ic_transform_black_48dp', 'ic_tune_black_48dp', 'ic_view_comfy_black_48dp', 'ic_view_compact_black_48dp', 'ic_vignette_black_48dp', 'ic_wb_auto_black_48dp', 'ic_wb_cloudy_black_48dp', 'ic_wb_incandescent_black_48dp', 'ic_wb_iridescent_black_48dp', 'ic_wb_sunny_black_48dp', 'ic_add_location_black_48dp', 'ic_beenhere_black_48dp', 'ic_directions_bike_black_48dp', 'ic_directions_black_48dp', 'ic_directions_boat_black_48dp', 'ic_directions_bus_black_48dp', 'ic_directions_car_black_48dp', 'ic_directions_railway_black_48dp', 'ic_directions_run_black_48dp', 'ic_directions_subway_black_48dp', 'ic_directions_transit_black_48dp', 'ic_directions_walk_black_48dp', 'ic_edit_location_black_48dp', 'ic_ev_station_black_48dp', 'ic_flight_black_48dp', 'ic_hotel_black_48dp', 'ic_layers_black_48dp', 'ic_layers_clear_black_48dp', 'ic_local_activity_black_48dp', 'ic_local_airport_black_48dp', 'ic_local_atm_black_48dp', 'ic_local_bar_black_48dp', 'ic_local_cafe_black_48dp', 'ic_local_car_wash_black_48dp', 'ic_local_convenience_store_black_48dp', 'ic_local_dining_black_48dp', 'ic_local_drink_black_48dp', 'ic_local_florist_black_48dp', 'ic_local_gas_station_black_48dp', 'ic_local_grocery_store_black_48dp', 'ic_local_hospital_black_48dp', 'ic_local_hotel_black_48dp', 'ic_local_laundry_service_black_48dp', 'ic_local_library_black_48dp', 'ic_local_mall_black_48dp', 'ic_local_movies_black_48dp', 'ic_local_offer_black_48dp', 'ic_local_parking_black_48dp', 'ic_local_pharmacy_black_48dp', 'ic_local_phone_black_48dp', 'ic_local_pizza_black_48dp', 'ic_local_play_black_48dp', 'ic_local_post_office_black_48dp', 'ic_local_printshop_black_48dp', 'ic_local_see_black_48dp', 'ic_local_shipping_black_48dp', 'ic_local_taxi_black_48dp', 'ic_map_black_48dp', 'ic_my_location_black_48dp', 'ic_navigation_black_48dp', 'ic_near_me_black_48dp', 'ic_person_pin_black_48dp', 'ic_person_pin_circle_black_48dp', 'ic_pin_drop_black_48dp', 'ic_place_black_48dp', 'ic_rate_review_black_48dp', 'ic_restaurant_black_48dp', 'ic_restaurant_menu_black_48dp', 'ic_satellite_black_48dp', 'ic_store_mall_directory_black_48dp', 'ic_streetview_black_48dp', 'ic_subway_black_48dp', 'ic_terrain_black_48dp', 'ic_traffic_black_48dp', 'ic_train_black_48dp', 'ic_tram_black_48dp', 'ic_transfer_within_a_station_black_48dp', 'ic_zoom_out_map_black_48dp', 'ic_apps_black_48dp', 'ic_arrow_back_black_48dp', 'ic_arrow_downward_black_48dp', 'ic_arrow_drop_down_black_48dp', 'ic_arrow_drop_down_circle_black_48dp', 'ic_arrow_drop_up_black_48dp', 'ic_arrow_forward_black_48dp', 'ic_arrow_upward_black_48dp', 'ic_cancel_black_48dp', 'ic_check_black_48dp', 'ic_chevron_left_black_48dp', 'ic_chevron_right_black_48dp', 'ic_close_black_48dp', 'ic_expand_less_black_48dp', 'ic_expand_more_black_48dp', 'ic_first_page_black_48dp', 'ic_fullscreen_black_48dp', 'ic_fullscreen_exit_black_48dp', 'ic_last_page_black_48dp', 'ic_menu_black_48dp', 'ic_more_horiz_black_48dp', 'ic_more_vert_black_48dp', 'ic_refresh_black_48dp', 'ic_subdirectory_arrow_left_black_48dp', 'ic_subdirectory_arrow_right_black_48dp', 'ic_unfold_less_black_48dp', 'ic_unfold_more_black_48dp', 'ic_adb_black_48dp', 'ic_airline_seat_flat_angled_black_48dp', 'ic_airline_seat_flat_black_48dp', 'ic_airline_seat_individual_suite_black_48dp', 'ic_airline_seat_legroom_extra_black_48dp', 'ic_airline_seat_legroom_normal_black_48dp', 'ic_airline_seat_legroom_reduced_black_48dp', 'ic_airline_seat_recline_extra_black_48dp', 'ic_airline_seat_recline_normal_black_48dp', 'ic_bluetooth_audio_black_48dp', 'ic_confirmation_number_black_48dp', 'ic_disc_full_black_48dp', 'ic_do_not_disturb_alt_black_48dp', 'ic_do_not_disturb_black_48dp', 'ic_do_not_disturb_off_black_48dp', 'ic_do_not_disturb_on_black_48dp', 'ic_drive_eta_black_48dp', 'ic_enhanced_encryption_black_48dp', 'ic_event_available_black_48dp', 'ic_event_busy_black_48dp', 'ic_event_note_black_48dp', 'ic_folder_special_black_48dp', 'ic_live_tv_black_48dp', 'ic_mms_black_48dp', 'ic_more_black_48dp', 'ic_network_check_black_48dp', 'ic_network_locked_black_48dp', 'ic_no_encryption_black_48dp', 'ic_ondemand_video_black_48dp', 'ic_personal_video_black_48dp', 'ic_phone_bluetooth_speaker_black_48dp', 'ic_phone_forwarded_black_48dp', 'ic_phone_in_talk_black_48dp', 'ic_phone_locked_black_48dp', 'ic_phone_missed_black_48dp', 'ic_phone_paused_black_48dp', 'ic_power_black_48dp', 'ic_priority_high_black_48dp', 'ic_rv_hookup_black_48dp', 'ic_sd_card_black_48dp', 'ic_sim_card_alert_black_48dp', 'ic_sms_black_48dp', 'ic_sms_failed_black_48dp', 'ic_sync_black_48dp', 'ic_sync_disabled_black_48dp', 'ic_sync_problem_black_48dp', 'ic_system_update_black_48dp', 'ic_tap_and_play_black_48dp', 'ic_time_to_leave_black_48dp', 'ic_vibration_black_48dp', 'ic_voice_chat_black_48dp', 'ic_vpn_lock_black_48dp', 'ic_wc_black_48dp', 'ic_wifi_black_48dp', 'ic_ac_unit_black_48dp', 'ic_airport_shuttle_black_48dp', 'ic_all_inclusive_black_48dp', 'ic_beach_access_black_48dp', 'ic_business_center_black_48dp', 'ic_casino_black_48dp', 'ic_child_care_black_48dp', 'ic_child_friendly_black_48dp', 'ic_fitness_center_black_48dp', 'ic_free_breakfast_black_48dp', 'ic_golf_course_black_48dp', 'ic_hot_tub_black_48dp', 'ic_kitchen_black_48dp', 'ic_pool_black_48dp', 'ic_room_service_black_48dp', 'ic_smoke_free_black_48dp', 'ic_smoking_rooms_black_48dp', 'ic_spa_black_48dp', 'ic_cake_black_48dp', 'ic_domain_black_48dp', 'ic_group_add_black_48dp', 'ic_group_black_48dp', 'ic_location_city_black_48dp', 'ic_mood_bad_black_48dp', 'ic_mood_black_48dp', 'ic_notifications_active_black_48dp', 'ic_notifications_black_48dp', 'ic_notifications_none_black_48dp', 'ic_notifications_off_black_48dp', 'ic_notifications_paused_black_48dp', 'ic_pages_black_48dp', 'ic_party_mode_black_48dp', 'ic_people_black_48dp', 'ic_people_outline_black_48dp', 'ic_person_add_black_48dp', 'ic_person_black_48dp', 'ic_person_outline_black_48dp', 'ic_plus_one_black_48dp', 'ic_poll_black_48dp', 'ic_public_black_48dp', 'ic_school_black_48dp', 'ic_sentiment_dissatisfied_black_48dp', 'ic_sentiment_neutral_black_48dp', 'ic_sentiment_satisfied_black_48dp', 'ic_sentiment_very_dissatisfied_black_48dp', 'ic_sentiment_very_satisfied_black_48dp', 'ic_share_black_48dp', 'ic_whatshot_black_48dp', 'ic_star_black_48dp', 'ic_star_border_black_48dp', 'ic_star_half_black_48dp'];
 ui.icons.setDataSource(icons);
 //让工具栏左上角可以打开侧拉菜单
ui.toolbar.setupWithDrawer(ui.drawer);
ui.menu.setDataSource([
    {
        title: "侠投林刷扬州",
        icon: "@drawable/ic_touch_app_black_48dp"
    },
    {
        title: "脚本设置",
        icon: "@drawable/ic_android_black_48dp"
    },
    {
        title: "运行日志",
        icon: "@drawable/ic_settings_black_48dp"
    },
    {
        title: "权限管理",
        icon: "@drawable/ic_favorite_black_48dp"
    },
    {
        title: "退出",
        icon: "@drawable/ic_exit_to_app_black_48dp"
    }
]);

ui.menu.on("item_click", item => {
    switch (item.title) {
        case "侠投林刷扬州":
            // 保存配置
    saveconfig()
    //程序开始运行之前判断无障碍服务
    if (auto.service == null) {
        toastLog("请先开启无障碍服务！");
        app.startActivity({
            action: "android.settings.ACCESSIBILITY_SETTINGS"
        });
        return;
    } else {
        log('已获取无障碍权限');
    }
    // 悬浮窗权限
    if (!runagain) {
        if (!floaty.checkPermission()) {
            // 没有悬浮窗权限，提示用户并跳转请求
            toastLog("请开启悬浮窗权限来显示悬浮窗，请在随后的界面中允许并重新运行本脚本。");
                    floaty.requestPermission();
                    return;
                } else {
                    log('已获取悬浮窗权限');
                }
            }
            // 激活码
            if (storage.get("jihuoma", "").length != 28) {
                toastLog("激活码错误，请打开系统设置选项验证激活码！");
                return;
            }
            // 设备信息   
            deviceJizhunFunc();
            // 右上悬浮窗
            xuanfuFunc()
            // 输出日志窗口
            xuanfuLogFunc()
            myLogFunc('分辨率：'+deviceWidth+'*'+deviceHeight)
            myLogFunc('分辨率基准：'+picJizhun)
            shuahanxinFunc();
            break;
        case "脚本设置":
            app.startActivity("settings");
            break;
        case "运行日志":
            app.startActivity("console");
            break;
        case "权限管理":
            app.openAppSetting("com.daoyikeji.yxssjxy");
            break;
        case "退出":
            ui.finish();
            break;
    }
})

// 侠投林刷图
function shuahanxinFunc() {
    myThreads = threads.start(function () {
        //截图权限自动化安卓版本高于Android 9
        if (device.sdkInt > 27) {
            //等待截屏权限申请并同意
            threads.start(function () {
                if (device.brand == "HUAWEI") {
                    packageName('com.android.systemui').text('允许').waitFor();
                    sleep(yanchi)
                    text('允许').click();
                } else {
                    packageName('com.android.systemui').text('立即开始').waitFor();
                    sleep(yanchi)
                    text('立即开始').click();
                }
            });
        }
        sleep(yanchi)
        //申请截屏权限
        if (!requestScreenCapture(true)) {
            toastLog("请求截图失败");
            exit()
        }

        if (storage.get("jihuoma", "").length != 28) {
            toastLog("激活码长度错误！");
            return;
        }
        let yangzhouShuia = dialogs.select("选择关卡","步兵二(玄精云母铁)","弓兵二(云母黄琥珀)","韩信","刘邦","项羽")
        log('yangzhouShuia',yangzhouShuia)
        storage.put("yangzhouShuia", yangzhouShuia);
        sleep(yanchi)
        app.launchPackage(gamePackageName);
        myLogFunc("打开游戏，确定在闯关且选将完成...")
        sleep(3000)

        // 林冲刷扬州
        dianhanxinFunc()
        
    })
}

// 刷林冲函数 点关卡头像
function dianhanxinFunc() {
    let thisImgs = null; // 韩信-hx_hanxin 刘邦-hx_liubang 吴三桂-hx_wusangui 项羽-hx_xiangyu
    let yangzhouShuia = storage.get("yangzhouShuia", '0')
    if (yangzhouShuia == 0) {
        thisImgs = images.read("./res/hx_bubinger.png");
    }
    if (yangzhouShuia == 1) {
        thisImgs = images.read("./res/hx_gongbinger.png");
    }
    if (yangzhouShuia == 2) {
        thisImgs = images.read("./res/hx_hanxin.png");
    }
    if (yangzhouShuia == 3) {
        thisImgs = images.read("./res/hx_liubang.png");
    }
    if (yangzhouShuia == 4) {
        thisImgs = images.read("./res/hx_xiangyu.png");
    }
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { threshold: 0.86 });
    thisImgs.recycle();
    if (p) {
        click(p.x,p.y)
        myLogFunc('进去关卡')
        sleep(yanchi)
        sleep(yanchi1)
        xuanlemei()
    }else{
        myLogFunc('等关卡_2s')
        sleep(yanchi2)
        dianhanxinFunc()
    }
}
function xuanlinchong() {
    let thisImgs = images.read("./res/hx_linchong.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { threshold: 0.81 });
    thisImgs.recycle();
    if (p) {
        click(p.x,p.y)
        sleep(yanchi)
    }
}
function xuanlemei() {
    let thisImgs = images.read("./res/hx_xuanzhujiang.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    // let p = findImage(captureScreen(), thisImgs);
    let result = images.matchTemplate(captureScreen(), thisImgs, { region: [0, 0, deviceWidth, (deviceHeight / 2)], threshold: 0.82, max: 2 });
    thisImgs.recycle();
    if (result.matches.length ) {
        myLogFunc("进行选将")
        xuanlinchong()
        let thisImgsElse = images.read("./res/英雄信息.png");
        thisImgsElse = images.scale(thisImgsElse, picJizhun, picJizhunHeight)
        let resultRc = images.matchTemplate(captureScreen(), thisImgsElse, { region: [0, (deviceHeight / 3), deviceWidth, (deviceHeight / 2)], threshold: 0.8, max: 8 });
        let matchRc = resultRc.sortBy("left-right").matches;
        for (let index = 0; index < matchRc.length; index++) {
            click(matchRc[index].point.x - 60, matchRc[index].point.y + 100);
            sleep(yanchi1)
            if (index > 3) {
                break;
            }
        }
        xuanlemei()
    }else{
        kaizhanla()
    }
}
function kaizhanla() {
    let thisImgs = images.read("./res/hx_kaizhan.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { threshold: 0.85 });
    thisImgs.recycle();
    if (p) {
        click(p.x,p.y)
        myLogFunc("开战")
        sleep(yanchi)
        sleep(yanchi1)
        hx_xiadanFunc()
    }
}
function chupaiquedingFunc(duoyanchi) {
    sleep(yanchi)
    let thisImgs2 = images.read("./res/hx_queding.png");
    thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
    let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.85 });
    thisImgs2.recycle();
    if (p2) {
        click(p2.x,p2.y)
        myLogFunc('确定出牌')
        if (duoyanchi) {
            sleep(yanchi3)
        } else {
            sleep(yanchi2)
        }
    }
}
function chupai1Func() {
    let cap = captureScreen()
    let thisImgs = images.read("./res/hx_shnegyou.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(cap, thisImgs, {region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.85 });
    thisImgs.recycle();
    if (p) {
        click(p.x,p.y)
        myLogFunc("无中生有")
        chupaiquedingFunc(true)
    }
}
function chupai2Func() {
    let cap = captureScreen()
    let thisImgs = images.read("./res/hx_hufu.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(cap, thisImgs, {region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.85 });
    thisImgs.recycle();
    if (p) {
        click(p.x,p.y)
        myLogFunc("虎符")
        chupaiquedingFunc()
    }
}
function hx_xiadanFunc() {
    let thisImgs = images.read("./res/hx_xiadan.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { threshold: 0.85 });
    thisImgs.recycle();
    if (p) {
        // 可以出来
        chupai1Func()
        chupai2Func()
        click(p.x,p.y)
        myLogFunc("点击侠胆")
        sleep(yanchi1)
        let thisImgs1 = images.read("./res/hx_pindianyx.png");
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
        let p1 = findImage(captureScreen(), thisImgs1, { threshold: 0.63 });
        thisImgs1.recycle();
        if (p1) {
            log('可以拼点')
            hx_youjunFunc()
        }else{
            log('无法拼点')
        }
    }else{
        sleep(yanchi1)
        myLogFunc("等待")
        hx_xiadanFunc()
    }
}
function qipaiFunc() {
    let thisImgs1 = images.read("./res/hx_qipai.png");
    thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
    let p1 = findImage(captureScreen(), thisImgs1, { threshold: 0.65 });
    thisImgs1.recycle();
    if (p1) {
        log('需要弃牌')
        let thisImgs = images.read("./res/hx_meihua.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let result = images.matchTemplate(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8, max: 6 });
        thisImgs.recycle();
        log('hx_meihua',result.matches)
        if (result.matches.length ) {
            myLogFunc('选择弃牌')
            let matchRc = result.matches;
            for (let index = 0; index < matchRc.length; index++) {
                click(matchRc[index].point.x, matchRc[index].point.y);
                sleep(yanchi)
            }
            sleep(yanchi1)
            let thisImgs2 = images.read("./res/hx_queding.png");
            thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
            let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.85 });
            thisImgs2.recycle();
            if (p2) {
                click(p2.x,p2.y)
                myLogFunc('确定弃牌')
                sleep(yanchi1)
            }
        }else{
            qipaiFangpian()
        }
    }else{
        log('无需弃牌')
    }
}
function qipaiFangpian() {
    let thisImgs = images.read("./res/hx_pianzi.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let result = images.matchTemplate(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8, max: 6 });
        thisImgs.recycle();
        log('hx_pianzi',result.matches)
        if (result.matches.length ) {
            myLogFunc('选择弃牌方片')
            let matchRc = result.matches;
            for (let index = 0; index < matchRc.length; index++) {
                click(matchRc[index].point.x, matchRc[index].point.y);
                sleep(yanchi)
            }
            sleep(yanchi1)
            let thisImgs2 = images.read("./res/hx_queding.png");
            thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
            let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.85 });
            thisImgs2.recycle();
            if (p2) {
                click(p2.x,p2.y)
                myLogFunc('确定弃牌')
                sleep(yanchi1)
            }
        }else{
            myLogFunc('等待自动弃牌')
        }
}
function hx_xiadanFunc11() {
    myLogFunc("等待1")
    sleep(yanchi1)
    // 找侠胆
    let thisImgs = images.read("./res/hx_xiadan.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { threshold: 0.85 });
    thisImgs.recycle();
    if (p) {
        // 可以出来
        chupai1Func()
        chupai2Func()
        click(p.x,p.y)
        myLogFunc("点击侠胆")
        sleep(yanchi1)
        let thisImgs1 = images.read("./res/hx_pindianyx.png");
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
        let p1 = findImage(captureScreen(), thisImgs1, { threshold: 0.65 });
        thisImgs1.recycle();
        if (p1) {
            log('可以拼点1')
            hx_youjunFunc()
        }else{
            log('无法拼点1')
        }
    }else{
        chupaiquedingFunc()
        sleep(yanchi2)
        myLogFunc("等待2")
        let hx_baoxiang = images.read("./res/hx_baoxiang.png");
        hx_baoxiang = images.scale(hx_baoxiang, picJizhun, picJizhunHeight)
        let phx = findImage(captureScreen(), hx_baoxiang, { threshold: 0.85 });
        hx_baoxiang.recycle();
        if (phx) {
            click(phx.x,phx.y)
            myLogFunc('宝箱2')
            sleep(yanchi)
            fanhuiaFunc()
        }else{
            let hx_fanhui = images.read("./res/hx_fanhui.png");
            hx_fanhui = images.scale(hx_fanhui, picJizhun, picJizhunHeight)
            let pfh = findImage(captureScreen(), hx_fanhui, { threshold: 0.85 });
            hx_fanhui.recycle();
            if (pfh) {
                click(pfh.x,pfh.y)
                myLogFunc('返回')
                sleep(yanchi1)
                myLogFunc('重新开始')
                dianhanxinFunc()
            }else{
                sleep(yanchi1)
                hx_xiadanFunc11()
            }
        }
    }
}
function hx_youjunFunc() {
    let thisImgs = images.read("./res/hx_youjun.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, {  region: [0, 0, deviceWidth, (deviceHeight / 2)], threshold: 0.85 });
    thisImgs.recycle();
    if (p) {
        log('p',p)
        click(p.x+50,p.y+100)
        myLogFunc("选取友军1")
        sleep(yanchi1)
        let thisImgs1 = images.read("./res/hx_queding.png");
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
        let p1 = findImage(captureScreen(), thisImgs1, { threshold: 0.85 });
        thisImgs1.recycle();
        if (p1) {
            click(p1.x,p1.y)
            myLogFunc('确定')
            sleep(yanchi1)
            xuanpai(13)
        }
    }
}
function xuanpai(num) {
    myLogFunc(num)
        let imgStr = "./res/hx_pai_hei_"+num+".png";
        let thisImgs = images.read(imgStr);
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(captureScreen(), thisImgs, { threshold: 0.85 });
        if (p) {
            click(p.x,p.y)
            myLogFunc('选取较大牌'+ num)
            sleep(yanchi1)

            let thisImgs0 = images.read("./res/hx_youjun.png");
            thisImgs0 = images.scale(thisImgs0, picJizhun, picJizhunHeight)
            let p0 = findImage(captureScreen(), thisImgs0, { threshold: 0.85 });
            thisImgs0.recycle();
            if (p0) {
                log('p0',p0)
                click(p0.x+100,p0.y+100)
                myLogFunc('选取友军2')
                sleep(yanchi1)

                let thisImgs1 = images.read("./res/hx_queding.png");
                thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
                let p1 = findImage(captureScreen(), thisImgs1, { threshold: 0.85 });
                thisImgs1.recycle();
                if (p1) {
                    click(p1.x,p1.y)
                    myLogFunc('确定2')
                    sleep(yanchi1)

                    hx_shaaFunc()
                    sleep(yanchi1)
                    myLogFunc('杀了1')
                    // 第二次杀等待
                    sleep(yanchi3)
                    hx_shaaFunc()
                    myLogFunc('杀了2')
                    jieshuchupaiFunc()
                }
            }else{
                myLogFunc('选取友军失败')
            }

            
        } else {
            num = num - 1
            xuanpai(num)
        }
}

function hx_shaaFunc() {
    let thisImgs = images.read("./res/hx_shaa.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let result = images.matchTemplate(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8, max: 6 });
    thisImgs.recycle();
    log('result.matches',result.matches)
    if (result.matches.length ) {
        myLogFunc(result.matches.length+'张杀')
        // let matches = result.matches[result.matches.length-1]
        let p = result.first().point;
        if (p) {
            click(p.x, p.y);
            myLogFunc('选择杀')
            sleep(yanchi1)

            // 选敌军
            let thisImgs0 = images.read("./res/hx_diren.png");
            thisImgs0 = images.scale(thisImgs0, picJizhun, picJizhunHeight)
            // let p0 = findImage(captureScreen(), thisImgs0, { threshold: 0.85 });
            let result0 = images.matchTemplate(captureScreen(), thisImgs0, { region: [0, 0, deviceWidth, (deviceHeight / 2)], threshold: 0.85, max: 2 });
            log('敌人', result0)
            thisImgs0.recycle();
            if (result0.matches.length ) {
                myLogFunc('选择敌人')
                let matchRc = result0.matches;
                for (let index = 0; index < matchRc.length; index++) {
                    if (index > 1) {
                        break;
                    }
                    click(matchRc[index].point.x + 80, matchRc[index].point.y + 100);
                    sleep(yanchi1)
                }
            }

            // 11111
            let thisImgs1 = images.read("./res/hx_queding.png");
            thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
            let p1 = findImage(captureScreen(), thisImgs1, { threshold: 0.85 });
            thisImgs1.recycle();
            if (p1) {
                click(p1.x,p1.y)
                myLogFunc('确定')
                sleep(yanchi3)
            }

        }
    }else{
        myLogFunc('结束')
    }
}

function jieshuchupaiFunc() {
    let thisImgs = images.read("./res/hx_jieshuchupai.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { threshold: 0.85 });
    thisImgs.recycle();
    if (p) {
        click(p.x,p.y)
        myLogFunc('结束出牌')
        sleep(yanchi1)
        // 弃牌流程 ***
        qipaiFunc()
        hx_xiadanFunc11()
    }else{
        sleep(yanchi2)
        myLogFunc("等待结束")
        let hx_baoxiang = images.read("./res/hx_baoxiang.png");
        hx_baoxiang = images.scale(hx_baoxiang, picJizhun, picJizhunHeight)
        let phx = findImage(captureScreen(), hx_baoxiang, { threshold: 0.85 });
        hx_baoxiang.recycle();
        if (phx) {
            click(phx.x,phx.y)
            myLogFunc('宝箱1')
            sleep(yanchi)
            fanhuiaFunc()
        }else{
            sleep(yanchi)
            fanhuiaFunc()
        }
    }
}

function fanhuiaFunc() {
    let hx_fanhui = images.read("./res/hx_fanhui.png");
    hx_fanhui = images.scale(hx_fanhui, picJizhun, picJizhunHeight)
    let pfh = findImage(captureScreen(), hx_fanhui, { threshold: 0.8 });
    hx_fanhui.recycle();
    if (pfh) {
        click(pfh.x,pfh.y)
        myLogFunc('返回')
        sleep(yanchi1)
        myLogFunc('重新开始')
        dianhanxinFunc()
    }else{
        sleep(yanchi1)
        jieshuchupaiFunc()
    }
}


// 基础函数配置
function swipeRandom(qx, qy, zx, zy, time) {
    swipe(qx, qy, zx, zy, time)
}

// 用户输出
function myLogFunc() {
    log(arguments)
    myLogStr += '\n' + String(arguments[0])
    //对控件的操作需要在UI线程中执行
    ui.run(function(){
        floatyConsole.myLog.text(" " + myLogStr + " ");
    });
}

// 保存配置
function saveconfig() {
    storage.put("jihuoma", ui.jihuoma.text());
    storage.put("tianxuan", ui.tianxuan.checked);
    storage.put("junbao", ui.junbao.checked);
    storage.put("zhengshou", ui.zhengshou.checked);
    storage.put("lingqurenwu", ui.lingqurenwu.checked)
    storage.put("isdaye", ui.isdaye.checked)
    storage.put("ye1", ui.ye1.checked)
    storage.put("ye2", ui.ye2.checked)
    storage.put("ye3", ui.ye3.checked)
    storage.put("ye4", ui.ye4.checked)
    storage.put("ye5", ui.ye5.checked)
    storage.put("ye6", ui.ye6.checked)
    storage.put("ye7", ui.ye7.checked)
    storage.put("shuayewushang", ui.shuayewushang.checked)
    storage.put("caijiquyuDy", ui.caijiquyuDy.checked);
    storage.put("zuoshang", ui.zuoshang.checked);
    storage.put("zuozhong", ui.zuozhong.checked);
    storage.put("zuoxia", ui.zuoxia.checked);
    storage.put("youshang", ui.youshang.checked);
    storage.put("youzhong", ui.youzhong.checked);
    storage.put("youxia", ui.youxia.checked);
    storage.put("jaincedenglu", ui.jaincedenglu.checked);
    storage.put("denglufangshi", ui.denglufangshi.getSelectedItemPosition());
    storage.put("yunxingfangshi", ui.yunxingfangshi.getSelectedItemPosition());

    // 采集配置
    storage.put("caijiziyuan", ui.caijiziyuan.checked);
    storage.put("zhicaifujin", ui.zhicaifujin.checked);
    storage.put("beixuanziyuan", ui.beixuanziyuan.checked);
    storage.put("caijiyouxian", ui.caijiyouxian.getSelectedItemPosition());
    storage.put("baohanziji", ui.baohanziji.checked);
    storage.put("centerZhucheng", ui.centerZhucheng.checked);
    storage.put("changfangxingDy", ui.changfangxingDy.checked);
    storage.put("islingdidenglu", ui.islingdidenglu.checked);
    storage.put("beixuanziyuanFw", ui.beixuanziyuanFw.text());
    storage.put("centerNPing", ui.centerNPing.text());
    storage.put("fangxingPing", ui.fangxingPing.text());
    storage.put("intermission", ui.intermission.text());
    storage.put("lingdidenglu", ui.lingdidenglu.text());
    storage.put("caijibaoliuHero", ui.caijibaoliuHero.text());
    storage.put("shuayebaoliu", ui.shuayebaoliu.text());
    storage.put("cunliangNum", ui.cunliangNum.text());
    storage.put("cunliangNumSy", ui.cunliangNumSy.text());

    // 敌袭配置
    storage.put("openDixi", ui.openDixi.checked);
    storage.put("dixiyuyin", ui.dixiyuyin.checked);
    storage.put("dixizhendong", ui.dixizhendong.checked);
    storage.put("dixiyoujian", ui.dixiyoujian.checked);
    storage.put("userrEmail", ui.userrEmail.text());

    storage.put("logFile", ui.logFile.checked);
    storage.put("zhenjibaohuo", ui.zhenjibaohuo.checked);
    storage.put("caijiItems", toCaijiList);
    if (Number(ui.yanchisulv.text()) < 0.5) {
        storage.put("delayBase", "0.5")
    }else{
        storage.put("delayBase", ui.yanchisulv.text())
    }
    
    // 配置默认数据
    duiwushangxian = Boolean(storage.get("tianxuan", true)) ? 3 : 2;
}

function readconfig() {
    ui.jihuoma.text(storage.get("jihuoma", ""));
    ui.tianxuan.checked = Boolean(storage.get("tianxuan", true));
    ui.junbao.checked = Boolean(storage.get("junbao", true));
    ui.zhengshou.checked = Boolean(storage.get("zhengshou", false));
    ui.lingqurenwu.checked = Boolean(storage.get("lingqurenwu", false));
    ui.isdaye.checked = Boolean(storage.get("isdaye", true));
    ui.ye1.checked = Boolean(storage.get("ye1", false));
    ui.ye2.checked = Boolean(storage.get("ye2", false));
    ui.ye3.checked = Boolean(storage.get("ye3", false));
    ui.ye4.checked = Boolean(storage.get("ye4", false));
    ui.ye5.checked = Boolean(storage.get("ye5", false));
    ui.ye6.checked = Boolean(storage.get("ye6", false));
    ui.ye7.checked = Boolean(storage.get("ye7", false));
    ui.shuayewushang.checked = Boolean(storage.get("shuayewushang", false));
    ui.caijiquyuDy.checked = Boolean(storage.get("caijiquyuDy", false));
    ui.zuoshang.checked = Boolean(storage.get("zuoshang", false));
    ui.zuozhong.checked = Boolean(storage.get("zuozhong", false));
    ui.zuoxia.checked = Boolean(storage.get("zuoxia", false));
    ui.youshang.checked = Boolean(storage.get("youshang", false));
    ui.youzhong.checked = Boolean(storage.get("youzhong", false));
    ui.youxia.checked = Boolean(storage.get("youxia", false));
    ui.jaincedenglu.checked = Boolean(storage.get("jaincedenglu", false));


    if (parseInt(storage.get("denglufangshi", 0))) {
        ui.denglufangshi.setSelection(parseInt(storage.get("denglufangshi", 0)));
    };
    if (parseInt(storage.get("yunxingfangshi", 1))) {
        ui.yunxingfangshi.setSelection(parseInt(storage.get("yunxingfangshi", 1)));
    };
    if (parseInt(storage.get("caijiyouxian", 0))) {
        ui.caijiyouxian.setSelection(parseInt(storage.get("caijiyouxian", 0)));
    };
    // 采集配置
    ui.caijiziyuan.checked = Boolean(storage.get("caijiziyuan", true));
    ui.zhicaifujin.checked = Boolean(storage.get("zhicaifujin", false));
    ui.beixuanziyuan.checked = Boolean(storage.get("beixuanziyuan", true));
    ui.beixuanziyuanFw.text(storage.get("beixuanziyuanFw", "3"));
    ui.centerNPing.text(storage.get("centerNPing", "1"));
    ui.fangxingPing.text(storage.get("fangxingPing", "108,88,138,108"));
    ui.intermission.text(storage.get("intermission", "1"));
    ui.lingdidenglu.text(storage.get("lingdidenglu", "20"));
    ui.baohanziji.checked = Boolean(storage.get("baohanziji", false));
    ui.centerZhucheng.checked = Boolean(storage.get("centerZhucheng", true));
    ui.changfangxingDy.checked = Boolean(storage.get("changfangxingDy", false));
    ui.islingdidenglu.checked = Boolean(storage.get("islingdidenglu", false));
    ui.ziyuancunchu.checked = Boolean(storage.get("ziyuancunchu", false));
    ui.caijibaoliuHero.text(storage.get("caijibaoliuHero", "0"));
    ui.shuayebaoliu.text(storage.get("shuayebaoliu", "0"));
    ui.cunliangNum.text(storage.get("cunliangNum", "19999"));
    ui.cunliangNumSy.text(storage.get("cunliangNumSy", "10"));

    // 敌袭配置
    ui.openDixi.checked = Boolean(storage.get("openDixi", false));
    ui.dixiyuyin.checked = Boolean(storage.get("dixiyuyin", false));
    ui.dixizhendong.checked = Boolean(storage.get("dixizhendong", false));
    ui.dixiyoujian.checked = Boolean(storage.get("dixiyoujian", false));
    ui.userrEmail.text(storage.get("userrEmail", ""));

    ui.logFile.checked = Boolean(storage.get("logFile", true));
    ui.zhenjibaohuo.checked = Boolean(storage.get("zhenjibaohuo", false));
    ui.yanchisulv.text(String(storage.get("delayBase", "1")));
}
// 读取配置写入界面
readconfig()

function mainFunc(again) {
    log("main0")
    myThreads = null;
    dixiTishi = true;
    log("main1")
    myThreads = threads.start(function () {
        log("myThreads线程")
        // 配置初始化变量
        shouyejinru = false;
        // 检查无障碍服务是否已经启用，如果没有启用则跳转到无障碍服务启用界面，并等待无障碍服务启动；当无障碍服务启动后脚本会继续运行。
        auto.waitFor()
        if (again && !runagain) {
            log("截图权限")
            //截图权限自动化安卓版本高于Android 9
            if (device.sdkInt > 27) {
                //等待截屏权限申请并同意
                threads.start(function () {
                    if (device.brand == "HUAWEI") {
                        packageName('com.android.systemui').text('允许').waitFor();
                        sleep(yanchi)
                        text('允许').click();
                    } else {
                        packageName('com.android.systemui').text('立即开始').waitFor();
                        sleep(yanchi)
                        text('立即开始').click();
                    }
                });
            }
            sleep(yanchi)
            //申请截屏权限
            if (!requestScreenCapture(true)) {
                toastLog("请求截图失败");
                exit()
            }
        }
        runagain = true;
        // 请求服务
        if (isPulic) {
            let req = http.postJson("http://123.60.43.199:8866/main/v1/auto/yxsXysjApp", {
                activationCode: storage.get("jihuoma", ""),
                aap: "yxsXysj",
                deviceWidth: device.width,
                deviceHeight: device.height,
                brand: device.brand,
                versionCode: project.versionCode,
                release: device.release,
                sdkInt: device.sdkInt,
                androidId: device.getAndroidId(),
                fingerprint: device.fingerprint,
                // mac: device.getMacAddress(), //雷电5崩溃
                // iMEI: device.getIMEI(), // 需要权限 否则报错
                startTime: new Date().getTime()
            });
            let rJson = req.body.json();
            if (rJson.code != 200) {
                let message = rJson.message ? rJson.message : "服务异常请联系客服！";
                toastLog(message)
                sleep(2000)
                exit()
                sleep(2000)
                ui.finish()
            } else {
                myLogFunc("服务成功注册！")
            }
        } else {
            myLogFunc("跳过服务注册！")
        }
        
        sleep(yanchi1)
        // 启动游戏
        let appPackName = currentPackage();
        myLogFunc("启动游戏", appPackName)
        if (appPackName != gamePackageName) {
            app.launchPackage(gamePackageName);
            myLogFunc("游戏启动中，请稍等...")
            sleep(5000)
            appPackName = currentPackage();
            if (appPackName == gamePackageName) {
                myLogFunc("游戏已打开，请稍等...")
            }
            if (isPulic) {
                sleep(15000)
            } else {
                sleep(yanchi1)
            }
        } else {
            myLogFunc("游戏正在运行");
        }


        // 启动程序
        sleep(yanchi2)
        // 主程序入口
        if (isPulic) {
            LoginFunc()
        } else {
            ShijieShouyeFunc()
        }

    })
}

// 重写延迟
function rewriteDelayFunc(num) {
    myLogFunc("本机反应较慢_增加延迟时间");
    myLogFunc("原延迟基准"+delayBase);
    num = delayBase * num
    if (num > 2.5) {
        myLogFunc("触发延迟安全值，请联系管理员");
        return;
    }
    myLogFunc("新延迟基准"+num);
    storage.put("delayBase", num);
    delayBase = Number(storage.get("delayBase", "1"));
    log('delayBase',delayBase)
    let yanchiBase = 500;
    yanchi = yanchiBase * delayBase; // 点击后停顿
    yanchi1 = yanchiBase * 2 * delayBase; // 点击前停顿
    yanchi2 = yanchiBase * 4 * delayBase; // 点击后停顿
    yanchi3 = yanchiBase * 6 * delayBase; // 点击后停顿
    yanchi5 = yanchiBase * 10 * delayBase; // 点击后停顿
    log('yanchi',yanchi,yanchi1,yanchi2,yanchi3,yanchi5)
}

// 设备基准
function deviceJizhunFunc() {
    delayBase = Number(storage.get("delayBase", "1"));
    yanchi = 500 * delayBase; // 点击后停顿
    yanchi1 = 1000 * delayBase; // 点击前停顿
    yanchi2 = 2000 * delayBase; // 点击后停顿
    yanchi3 = 3000 * delayBase; // 点击后停顿
    yanchi5 = 5000 * delayBase; // 点击后停顿

    shangciweizhi = storage.get("shangciweizhi", { x: 0, y: 0 }); // 上次位置坐标
    xiaodituPosit = storage.get("xiaodituPosit", { x: 0, y: 0 }); // 小地图起始位置
    cunliangWeizhi = storage.get("cunliangWeizhi", { x: 0, y: 0, w: 260, h: 45 }); // 存量起始位置
    yingxiongMsgWeizhi = storage.get("yingxiongMsgWeizhi", { x: 0, y: 0, w: 300, h: 0 }); // 英雄信息坐标
    ziyuanZuobianWeizhi = storage.get("ziyuanZuobianWeizhi", { x: 0, y: 0, w: 300, h: 65 }); // 资源信息坐标 

    deviceWidth = device.width > device.height ? device.width : device.height;
    deviceHeight = device.height > device.width ? device.width : device.height;
    picJizhun = deviceHeight / 1080;
    picJizhunHeight = deviceHeight / 1080;
    if (deviceHeight == 720) {
        picJizhun = 0.666666666666667;
        picJizhunHeight = 0.666666666666667;
    }
    if (deviceHeight == 1200) {
        picJizhun = 1.12;
        picJizhunHeight = 1.12;
    }
    let h = 80*picJizhun;
    if (h < 65) {
        h = 65
    }
    youshangDuilie = { x:deviceWidth - (880*picJizhun), y:(159*picJizhun), w:(880*picJizhun), h: h }
}

// 悬浮窗
function xuanfuLogFunc() {
    floatyConsole = floaty.rawWindow(
        <frame gravity="left">
            <text id="myLog" text="日志" textColor="#ffffff" textSize="8sp" ellipsize="marquee" gravity="bottom" />
        </frame>
    );
    let w = 358 * picJizhun
    let h = 188 * picJizhun
    floatyConsole.setSize(w, h)
    floatyConsole.setPosition(5, device.width - h);
    floatyConsole.setTouchable(false)
    floatyConsole.myLog.text(" " + myLogStr + " ");
}

// 悬浮窗
function xuanfuFunc() {
    floatyWindow = floaty.window(
        <horizontal >
            <button id="floatyAction" text="运" textSize="9sp" w="25" h="25" padding="0sp"></button>
            <button id="peizhishezhi" text="设置" textSize="8sp" w="38" h="25" bg="#7E8EBF" marginLeft="8sp" padding="0sp"/>
            <button id="ziyuanpeizhi" text="资源" textSize="8sp" w="38" h="25" bg="#7E8EBF" marginLeft="2sp" padding="0sp"/>
            <button id="myExit" text="退" textSize="8sp" w="25" h="25" bg="#02FE99" marginLeft="2sp" padding="0sp"/>
        </horizontal >
    );

    floatyWindow.floatyAction.setOnTouchListener(function (view, event) {
        switch (event.getAction()) {
            case event.ACTION_DOWN:
                x = event.getRawX();
                y = event.getRawY();
                windowX = floatyWindow.getX();
                windowY = floatyWindow.getY();
                return true;
            case event.ACTION_MOVE:
                //移动手指时调整悬浮窗位置
                floatyWindow.setPosition(windowX + (event.getRawX() - x), windowY + (event.getRawY() - y));
                return true;
            case event.ACTION_UP:
                //手指弹起时如果偏移很小则判断为点击
                if (Math.abs(event.getRawY() - y) < 5 && Math.abs(event.getRawX() - x) < 5) {
                    // myLogFunc('点击悬浮窗')
                    floatyActionOnClick();
                }
                return true;
        }
        return true;
    });
    floatyWindow.myExit.on("click", function () {
        ui.finish()
    })
    floatyWindow.peizhishezhi.on("click", function () {
        if (isPulic) {
            caijiduiwu = 0;
            myLogStr = "";
            floatyConsole.close()
            app.launchPackage("com.daoyikeji.yxssjxy");
            floatyWindow.close()
        } else {
            caijiduiwu = 0;
            myLogStr = "";
            floatyConsole.close()
            app.launchPackage("org.autojs.autoxjs.v6");
            floatyWindow.close()
        }
    })
    // 资源配置
    floatyWindow.ziyuanpeizhi.on("click", function () {
        // 首次配置资源坐标位置
        log(1)
        if (ziyuanZuobianWeizhi.x == 0) {
            log(2)
            myLogFunc('首次配置资源坐标位置')
            log(3)
            let thisImgs1 = images.read("./res/坐标背景图.png");
            log(4)
            thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
            log(5)
            let p1 = findImage(captureScreen(), thisImgs1, { region: [0, 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
            log(6)
            thisImgs1.recycle();
            log("p1", p1)
            if (p1) {
                myLogFunc('资源坐标位置配置完成')
                ziyuanZuobianWeizhi.x = p1.x + 50
                ziyuanZuobianWeizhi.y = p1.y
                storage.put("ziyuanZuobianWeizhi", ziyuanZuobianWeizhi);
            }else{
                log('资源坐标位置配置失败！')
            }
        }
        let cap = captureScreen()
        let clip = images.clip(cap, ziyuanZuobianWeizhi.x-80, ziyuanZuobianWeizhi.y, (400*picJizhun), (200*picJizhunHeight));
        let orcRes = paddle.ocrText(clip);
        clip.recycle();
        log("坐标截取", orcRes)

            let xy = orcRes[0];
            let xy0 = xy[0]
            if (isNaN(xy0)) {
                if (xy.includes('(') || xy.includes('（')) {
                    xy = xy.substring(1, xy.length)
                }
            }
            let xy3 = xy[xy.length]
            if (isNaN(xy3)) {
                if (xy.includes(')') || xy.includes('）')) {
                    xy = xy.substring(0, xy.length - 1)   
                }
            }
            xy = xy.replace("口", "0");
            xy = xy.replace("日", "8");

            let douhao = ',';
            if (xy.includes('，')) {
                douhao = '，';
            }
            if (xy.includes('.')) {
                douhao = '.';
            }
            let xyArr = xy.split(douhao)

            
            if (isNaN(xyArr[0]) || isNaN(xyArr[1])) {
                myLogFunc('读取失败，请手动添加')
            } else {
                myLogFunc('坐标 X:'+xyArr[0]+' Y:'+xyArr[1])
                let type = 0
                for (let index = 0; index < orcRes.length; index++) {
                    let element = orcRes[index];
                    if (element.includes('田')) {
                        type = 0
                    }
                    if (element.includes('木')) {
                        type = 1
                    }
                    if (element.includes('矿')) {
                        type = 2
                    }
                }

                toCaijiList.push({
                    x: xyArr[0],
                    y: xyArr[1],
                    level: 1,
                    type: type
                });
                myLogFunc("添加完成")
                storage.put("caijiItems", toCaijiList);
                }
    })
    floatyWindow.setPosition(168, 12);
    floatyWindow.peizhishezhi.setVisibility(8);
    floatyWindow.ziyuanpeizhi.setVisibility(8);
    floatyWindow.myExit.setVisibility(8);
    setBackgroundRoundRounded(floatyWindow.floatyAction, Color.GREEN);
}

// 设置按钮样式
function setBackgroundRoundRounded(view, bloo) {
    gradientDrawable = new GradientDrawable();
    gradientDrawable.setShape(GradientDrawable.RECTANGLE);
    gradientDrawable.setColor(bloo);
    gradientDrawable.setCornerRadius(80);
    view.setBackground(gradientDrawable);
}

// 悬浮窗按钮点击
function floatyActionOnClick() {
    if (floatyWindow.floatyAction.getText() == '运') {
        //停止线程执行
        if (myThreads) {
            myThreads.interrupt();
        }
        myThreads = null;
        setBackgroundRoundRounded(floatyWindow.floatyAction, Color.RED);
        floatyWindow.peizhishezhi.setVisibility(0);
        floatyWindow.ziyuanpeizhi.setVisibility(0);
        floatyWindow.myExit.setVisibility(0);
        floatyWindow.floatyAction.setText('停');
        myLogFunc("停止")
    } else if (floatyWindow.floatyAction.getText() == '停') {
        threads.shutDownAll()
        floatyWindow.peizhishezhi.setVisibility(8);
        floatyWindow.ziyuanpeizhi.setVisibility(8);
        floatyWindow.myExit.setVisibility(8);
        setBackgroundRoundRounded(floatyWindow.floatyAction, Color.GREEN);
        floatyWindow.floatyAction.setText('运');
        mainFunc()
        myLogFunc("再次运行...")
    } else {
        myLogFunc("？？？...")
    }
}

function yichangFanhuiFunc() {
    let thisImgs2 = images.read("./res/签到关闭按钮.png");
    thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
    let p2 = findImage(captureScreen(), thisImgs2);
    thisImgs2.recycle();
    if (p2) {
        sleep(yanchi)
        click(p2.x + 5, p2.y + 5)
        sleep(yanchi2)
    }else{
        let thisImgs3 = images.read("./res/首页挑战.png");
        thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
        let p3 = findImage(captureScreen(), thisImgs3);
        thisImgs3.recycle();
        if (p3) {
            myLogFunc('在游戏首页')
            sleep(yanchi1)
            let y = p3.y - (150*picJizhun)
            click(p3.x , y);
            sleep(yanchi2)
            shouyejinru = true;
            // 进入世界页面
            sleep(yanchi2)
            ShijieShouyeFunc()
        } else {
            myLogFunc('按键返回')
            back()
        }
    }
}

// 查看世界地图
function seeShijieditu() {
    let thisImgs = images.read("./res/世界地图按钮.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs);
    thisImgs.recycle();
    if (p) {
        myLogFunc('打开世界地图')
        sleep(yanchi)
        click(p.x, p.y)
        sleep(yanchi2)

        // 如果是第一次则配置地图 700*600
        if (xiaodituPosit.x == 0) {
            myLogFunc('第一次配置小地图参数')
            sleep(yanchi2)
            let thisImgs1 = images.read("./res/小地图.png");
            thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
            let p1 = findImage(captureScreen(), thisImgs1, { threshold: 0.9 });
            thisImgs1.recycle();
            if (p1) {
                // 以后小地图把p1点当作坐标 0,0
                log(p1)
                let newObj = { x: p1.x, y: p1.y };
                storage.put("xiaodituPosit", newObj);
                xiaodituPosit = storage.get("xiaodituPosit", { x: 0, y: 0 });
                // 700*600 成上基准值
            } else {
                toastLog("小地图信息异常")
                exit()
            }
        }
    } else {
        myLogFunc('打开地图失败')
        sleep(yanchi)
        yichangFanhuiFunc()
        sleep(yanchi1)
        seeShijieditu()
    }
}

// 关闭世界地图
function CloseShijieditu() {
    let thisImgs = images.read("./res/世界地图关闭.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs);
    thisImgs.recycle();
    if (p) {
        myLogFunc('关闭世界地图')
        sleep(yanchi)
        click(p.x, p.y)
        sleep(yanchi1)
    }
}

// 前往指定坐标 483就是16 进阶2.82 需要算法支持各种分辨率
function goXyFunc(x, y) {
    myLogFunc('前往坐标点', x, y)
    x = Number(x)
    y = Number(y)
    let zhia = parseInt(x / 50) + 1;
    let jiaozheng = 3;
    if (x < 127) {
        jiaozheng = 2;
    //     zhia = zhia - 1;
    }
    let xx = (xiaodituPosit.x + jiaozheng) + ((x + zhia) * (2.7558*picJizhun))
    let yy = xiaodituPosit.y + (y * (2.41*picJizhunHeight))
    sleep(yanchi1)
    log('采集点位置：', xx, yy)
    click(xx, yy)
    sleep(yanchi2)
}


// 查看联盟
function seeLianmengFunc() {
    let thisImgs = images.read("./res/联盟按钮.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.85 });
    thisImgs.recycle();
    if (p) {
        myLogFunc('点击联盟')
        sleep(yanchi)
        click(p.x, p.y)
        sleep(yanchi1)
        return true;
    } else {
        myLogFunc('error联盟按钮')
        return false;
    }
}

// 联盟建筑
function lianmengjianzhuFunc() {
    let thisImgs = images.read("./res/联盟建筑.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8 });
    thisImgs.recycle();
    if (p) {
        myLogFunc('点击联盟建筑')
        sleep(yanchi)
        click(p.x, p.y)
        sleep(yanchi1)
        return true;
    } else {
        myLogFunc('error联盟建筑')
        
            let thisImgs2 = images.read("./res/签到关闭按钮.png");
            thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
            let p2 = findImage(captureScreen(), thisImgs2);
            thisImgs2.recycle();
            if (p2) {
                sleep(yanchi)
                click(p2.x + 5, p2.y + 5)
                sleep(yanchi2)
            }else{
                let thisImgs3 = images.read("./res/首页挑战.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3);
                thisImgs3.recycle();
                if (p) {
                    myLogFunc('在游戏首页')
                    sleep(yanchi1)
                    let y = p.y - (150*picJizhun)
                    click(p.x , y);
                    sleep(yanchi2)
                    shouyejinru = true;
                    // 进入世界页面
                    sleep(yanchi2)
                    ShijieShouyeFunc()
                } else {
                    myLogFunc('按键返回_联盟建筑')
                    back()
                }
            }
        sleep(yanchi1)
        seeLianmengFunc()
        sleep(yanchi2)
        lianmengjianzhuFunc()
    }
}

// 前往联盟资源
function qianwangziyuanFunc(index) {
    let thisImgs = images.read("./res/前往联盟资源.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let result = images.matchTemplate(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.85, max: 2 });
    thisImgs.recycle();
    let matchRc = result.sortBy("left-right").matches;
    if (result) {
        log('前往联盟资源', matchRc.length, matchRc)
        if (matchRc.length < 2) {
            if (matchRc.length == 0) {
                yichangFanhuiFunc()
                return false;
            }
            let thisImgs1 = images.read("./res/建造资源.png");
            thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
            let p1 = findImage(captureScreen(), thisImgs1, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8 });
            thisImgs1.recycle();
            if (p1) {
                myLogFunc('未建联盟资源')
                back()
                sleep(yanchi1)
                return false;
            }else{
                myLogFunc('前往联盟资源_未建仓库')
                let p = matchRc[index].point;
                sleep(yanchi)
                click(p.x, p.y)
                sleep(yanchi5)
                let thisImgs2 = images.read("./res/联盟资源.png");
                thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
                let p2 = findImage(captureScreen(), thisImgs2);
                thisImgs2.recycle();
                if (p2) {
                    log('找到联盟资源')
                    click(deviceWidth / 2, deviceHeight / 2)
                    return true;  
                }else{
                    rewriteDelayFunc(1.2)
                    sleep(yanchi2)
                    click(deviceWidth / 2, deviceHeight / 2)
                    return true;  
                }
            }
        }else{
            myLogFunc('前往联盟资源')
            let p = matchRc[index].point;
            sleep(yanchi)
                click(p.x, p.y)
                sleep(yanchi5)
                let thisImgs2 = images.read("./res/联盟资源.png");
                thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
                let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.85 });
                thisImgs2.recycle();
                if (p2) {
                    log('找到联盟资源')
                    click(deviceWidth / 2, ((deviceHeight / 2)-2))
                    sleep(yanchi1)
                    return true;  
                }else{
                    log('未找到联盟资源发动延迟')
                    rewriteDelayFunc(1.2)
                    sleep(yanchi2)
                    click(deviceWidth / 2, ((deviceHeight / 2)-2))
                    sleep(yanchi1)
                    return true;  
                }
        }
    }else{
        myLogFunc('error联盟资源')
        return false;
    }
}


// 采集流程
function cajiAnniuFunc(bloo, bloo2) {
    let thisImgs = images.read("./res/资源采集_1155_930_1337_1030.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs);
    thisImgs.recycle();
    if (p) {
        if (!bloo) {
            if (cunliangWeizhi.x == 0) {
                myLogFunc('第一次配置存量信息')
                let thisImgs = images.read("./res/存量.png");
                thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
                let cunliangP = findImage(captureScreen(), thisImgs, { region: [(deviceWidth/2-100), 0, (deviceWidth/2), (deviceHeight / 2)], threshold: 0.85 });
                thisImgs.recycle();
                if (cunliangP) {
                    log(cunliangP.x, cunliangP.y)
                    let cunliangquyu = { x: cunliangP.x, y: cunliangP.y, w: parseInt(250 * picJizhun), h: parseInt(65 * picJizhunHeight) }
                    cunliangWeizhi = cunliangquyu;
                    log('cunliangquyu',cunliangquyu)
                    let clip = images.clip(captureScreen(), cunliangquyu.x, cunliangquyu.y, cunliangquyu.w, cunliangquyu.h);
                    let result = paddle.ocrText(clip);
                    log(result)
                    // 识别容错
                    if (result.length) {
                        result = result[0]
                    }else{
                        log('读取存量异常')
                        return false;
                    }
                    myLogFunc(result)
    
                    result = result.substring(2, result.length);
                    log(result)
                    if (result.includes("万")) {
                        log("万万");
                    } else {
                        if (Number(result) < Number(storage.get("cunliangNum", "19999"))) {
                            myLogFunc('资源存量不足1')
                            log(result,storage.get("cunliangNum", "19999"))
                            back();
                            sleep(yanchi)
                            return false;
                        }
                        log("不是过万资源");
                    }
    
                    storage.put("cunliangWeizhi", cunliangWeizhi);
                }
            } else {
                log('存量位置', cunliangWeizhi)
                let clip = images.clip(captureScreen(), cunliangWeizhi.x, cunliangWeizhi.y, cunliangWeizhi.w, cunliangWeizhi.h);
                let result = paddle.ocrText(clip);
                log(result)
                // 识别容错
                if (result.length) {
                    result = result[0]
                }else{
                    log('读取存量异常')
                    return false;
                }
                log(result)
                result = result.substring(2, result.length);
                log(result)
                if (result) {
                    if (result.includes("万")) {
                        log("万万");
                    } else {
                        if (Number(result) < Number(storage.get("cunliangNum", "19999"))) {
                            myLogFunc('资源存量不足')
                            log(result,storage.get("cunliangNum", "19999"))
                            back();
                            sleep(yanchi)
                            return false;
                        }
                        log("不是过万资源");
                    }
                } else {
                    myLogFunc('存量信息有误')
                }
    
            }
        }
        let thisImgsX = images.read("./res/采集上限.png");
        thisImgsX = images.scale(thisImgsX, picJizhun, picJizhunHeight)
        let pX = findImage(captureScreen(), thisImgsX);
        thisImgsX.recycle();
        if (pX) {
            caijiduiwu = duiwushangxian;
            click(10, (deviceHeight/2))
            sleep(yanchi1)
            back();
            sleep(yanchi)
            return false;
        }
        myLogFunc('资源可采集', p)
        sleep(yanchi)
        click(p.x, p.y);
        sleep(yanchi1)
        return true;
    } else {
        myLogFunc("资源不可采集");
        let thisImgs = images.read("./res/世界首页.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(captureScreen(), thisImgs, { threshold: 0.88 });
        thisImgs.recycle();
        if (p) {
            myLogFunc('世界模式首页啊')
            return false;
        } else {
            yichangFanhuiFunc()
            sleep(yanchi1)
            if (!bloo2) {
                caijiduilieFunc(true);
            }
            return false;
        }
    }
}

function caijiRcFunc() {
    log('查探是否可派兵')
    let thisImgsRc = images.read("./res/资源采集_1155_930_1337_1030.png");
    thisImgsRc = images.scale(thisImgsRc, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgsRc);
    thisImgsRc.recycle();
    if (p) {
        return true
    } else {
        return false
    }
}

// 界面异常处理 -- 超过采集
function chaoguocaiFunc() {
    let thisImgsRc = images.read("./res/签到关闭按钮.png");
    thisImgsRc = images.scale(thisImgsRc, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgsRc);
    thisImgsRc.recycle();
    if (p) {
        // 超过采集
        click(p.x,p.y)
        myLogFunc('关闭')
        sleep(yanchi1)
        chaoguocaiFunc()
        return true
    } else {
        log('不是超出采集')
        caijiduilieFunc(true);
        return false
    }
}

// 选择采集英雄
function caijiYingxiongFunc(bloo) {
    let cap = captureScreen()
    if (storage.get("caijiyouxian", "") == 0 && !bloo) {
        let thisImgs = images.read("./res/采集武将_1514_871_1649_935.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let result = images.matchTemplate(cap, thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8, max: 2 });
        thisImgs.recycle();
        if (result.matches.length) {
            myLogFunc('点击采集标志武将')
            let p = result.first().point;
            sleep(yanchi)
            click(p.x, p.y);
            sleep(yanchi1)
            // 有采集标志 判断兵力啊
            let thisImgsRc = images.read("./res/资源采集_no.png");
            thisImgsRc = images.scale(thisImgsRc, picJizhun, picJizhunHeight)
            let pRc = findImage(captureScreen(), thisImgsRc, { region: [0, 0, (deviceWidth / 2), (deviceHeight / 2)] });
            thisImgsRc.recycle();
            if (pRc) {
                myLogFunc('兵力不足')
                let thisImgsElse = images.read("./res/英雄信息.png");
                thisImgsElse = images.scale(thisImgsElse, picJizhun, picJizhunHeight)
                let resultRc = images.matchTemplate(captureScreen(), thisImgsElse, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.5, max: 8 });
                let matchRc = resultRc.sortBy("left-right").matches;
                let isChengLe = false;
                for (let index = 0; index < matchRc.length; index++) {
                    log('查探次数', index)
                    click(matchRc[index].point.x - 109, matchRc[index].point.y + 168.5);
                    sleep(yanchi1)
                    if (caijiRcFunc()) {
                        log('备用采集英雄')
                        isChengLe = true;
                        break;
                    }
                }
                if (!isChengLe) {
                    xiaobingbuzu = true;
                    myLogFunc('全体兵种不足')
                    back()
                    sleep(yanchi1)
                    back()
                    sleep(yanchi)
                }
            } else {
                log('兵力充足')
            }


        } else {
            myLogFunc('没有采集标志武将')
            myLogFunc('进入比分采集')
            log("0")
            let thisImgsElse = images.read("./res/英雄信息.png");
            // log("1")
            thisImgsElse = images.scale(thisImgsElse, picJizhun, picJizhunHeight)
            // log("2")
            let result = images.matchTemplate(cap, thisImgsElse, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.5, max: 8 });
            // log("3")
            thisImgsElse.recycle();
            if (result.matches.length) {
                let bestMatch = {}
                let bestNumber = 0;
                // log("4")
                result.sortBy("left-right").matches.forEach((match, indes) => {
                    if (indes >= storage.get("caijibaoliuHero", "0")) {
                        // log("5")
                        click(match.point.x - 109, match.point.y + 168.5);
                        // log("6")
                        sleep(yanchi1)
                        // 如果没有规划读取资源数据区域
                        if (yingxiongMsgWeizhi.x == 0) {
                            myLogFunc("没有配置采集数据区域")
                            let thisImgs1 = images.read("./res/资源负重.png");
                            thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
                            let thisImgs2 = images.read("./res/资源耗时.png");
                            thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
                            let p1 = findImage(cap, thisImgs1, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
                            let p2 = findImage(cap, thisImgs2, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
                            yingxiongMsgWeizhi.x = p1.x
                            yingxiongMsgWeizhi.y = p1.y
                            yingxiongMsgWeizhi.h = p2.y - p1.y
                            myLogFunc('采集数据区域', yingxiongMsgWeizhi)
                            storage.put("yingxiongMsgWeizhi", yingxiongMsgWeizhi);
                            yingxiongMsgWeizhi = storage.get("yingxiongMsgWeizhi", { x: 0, y: 0, w: 300, h: 0 }); // 英雄信息坐标
                        }


                        // 查看采集分和负重分做比较
                        let clip = images.clip(captureScreen(), yingxiongMsgWeizhi.x, yingxiongMsgWeizhi.y, yingxiongMsgWeizhi.w, yingxiongMsgWeizhi.h);
                        let res = paddle.ocr(clip);
                        clip.recycle();
                        let fraction = res[1].text.split('：')[1]
                        fraction = fraction.substring(0, fraction.length - 2)
                        // myLogFunc('采集速度：',fraction)
                        if (fraction > bestNumber) {
                            bestNumber = fraction;
                            bestMatch = match;
                        }

                    } else {
                        myLogFunc('跳过保留英雄')
                    }
                    sleep(yanchi)
                });

                sleep(yanchi)
                myLogFunc('采集分最高：' + bestNumber)
                click(bestMatch.point.x - 109, bestMatch.point.y + 168.5);
                sleep(yanchi1)

                let thisImgsRc = images.read("./res/资源采集_no.png");
                thisImgsRc = images.scale(thisImgsRc, picJizhun, picJizhunHeight)
                let p = findImage(captureScreen(), thisImgsRc, { region: [0, 0, (deviceWidth / 2), (deviceHeight / 2)] });
                thisImgsRc.recycle();
                if (p) {
                    myLogFunc('兵力不足')
                    let matchRc = result.sortBy("left-right").matches;
                    let isChengLe = false;
                    for (let index = 0; index < matchRc.length; index++) {
                        click(matchRc[index].point.x - 109, matchRc[index].point.y + 168.5);
                        sleep(yanchi1)
                        if (caijiRcFunc()) {
                            log('备用采集英雄')
                            isChengLe = true;
                            break;
                        }
                    }
                    if (!isChengLe) {
                        xiaobingbuzu = true;
                        myLogFunc('全体兵种不足')
                        back()
                        sleep(yanchi1)
                        back()
                        sleep(yanchi)
                    }
                }
            } else {
                myLogFunc('界面异常！')
                chaoguocaiFunc()
            }
        }
    } else {
        let thisImgs = images.read("./res/负重武将_568_869_692_937.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let result = images.matchTemplate(cap, thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8, max: 2 });
        thisImgs.recycle();
        if (result.matches.length) {
            log(result)
            myLogFunc('负重武将')
            let p = result.first().point;
            click(p.x, p.y);
            sleep(1500)
            // caijiChufaFunc();
            // 有采集标志 判断兵力啊
            let thisImgsRc = images.read("./res/资源采集_no.png");
            thisImgsRc = images.scale(thisImgsRc, picJizhun, picJizhunHeight)
            let pRc = findImage(captureScreen(), thisImgsRc, { region: [0, 0, (deviceWidth / 2), (deviceHeight / 2)] });
            thisImgsRc.recycle();
            if (pRc) {
                myLogFunc('兵力不足')
                let thisImgsElse = images.read("./res/英雄信息.png");
                thisImgsElse = images.scale(thisImgsElse, picJizhun, picJizhunHeight)
                let resultRc = images.matchTemplate(captureScreen(), thisImgsElse, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.5, max: 8 });
                let matchRc = resultRc.sortBy("left-right").matches;
                let isChengLe = false;
                for (let index = 0; index < matchRc.length; index++) {
                    click(matchRc[index].point.x - 109, matchRc[index].point.y + 168.5);
                    sleep(yanchi1)
                    if (caijiRcFunc()) {
                        log('备用负重英雄')
                        isChengLe = true;
                        break;
                    }
                }
                if (!isChengLe) {
                    xiaobingbuzu = true;
                    myLogFunc('全体兵种不足')
                    back()
                    sleep(yanchi1)
                    back()
                    sleep(yanchi)
                }
            }
        } else {
            myLogFunc('没有负重标志武将')
            myLogFunc('进入比分采集')

            let thisImgs = images.read("./res/英雄信息.png");
            thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
            let result = images.matchTemplate(cap, thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.5, max: 8 });
            thisImgs.recycle();
            if (result.matches.length) {
                let bestMatch = {}
                let bestNumber = 0;
                result.sortBy("left-right").matches.forEach(match => {
                    click(match.point.x - 109, match.point.y + 168.5);
                    sleep(yanchi)
                    // 如果没有规划读取资源数据区域
                    if (yingxiongMsgWeizhi.x == 0) {
                        myLogFunc("没有配置采集数据区域")
                        let thisImgs1 = images.read("./res/资源负重.png");
                        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
                        let thisImgs2 = images.read("./res/资源耗时.png");
                        thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
                        let p1 = findImage(cap, thisImgs1, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
                        let p2 = findImage(cap, thisImgs2, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
                        yingxiongMsgWeizhi.x = p1.x
                        yingxiongMsgWeizhi.y = p1.y
                        yingxiongMsgWeizhi.h = p2.y - p1.y
                        myLogFunc('采集数据区域', yingxiongMsgWeizhi)
                        storage.put("yingxiongMsgWeizhi", yingxiongMsgWeizhi);
                        yingxiongMsgWeizhi = storage.get("yingxiongMsgWeizhi", { x: 0, y: 0, w: 300, h: 0 }); // 英雄信息坐标
                    }


                    // 查看采集分和负重分做比较
                    let clip = images.clip(captureScreen(), yingxiongMsgWeizhi.x, yingxiongMsgWeizhi.y, yingxiongMsgWeizhi.w, yingxiongMsgWeizhi.h);
                    let res = paddle.ocr(clip);
                    clip.recycle();
                    let fraction = res[0].text.split('：')[1]
                    // myLogFunc('负重：',fraction)
                    if (fraction > bestNumber) {
                        bestNumber = fraction;
                        bestMatch = match;
                    }
                    sleep(yanchi)
                });

                sleep(yanchi)
                myLogFunc('负重最高：' + bestNumber)
                click(bestMatch.point.x - 109, bestMatch.point.y + 168.5);
                sleep(yanchi1)

                let thisImgsRc = images.read("./res/资源采集_no.png");
                thisImgsRc = images.scale(thisImgsRc, picJizhun, picJizhunHeight)
                let p = findImage(captureScreen(), thisImgsRc, { region: [0, 0, (deviceWidth / 2), (deviceHeight / 2)] });
                thisImgsRc.recycle();
                if (!p) {
                    myLogFunc('兵力不足')
                    let matchRc = result.sortBy("left-right").matches;
                    let isChengLe = false;
                    for (let index = 0; index < matchRc.length; index++) {
                        click(matchRc[index].point.x - 109, matchRc[index].point.y + 168.5);
                        sleep(yanchi1)
                        if (caijiRcFunc()) {
                            log('备用采集英雄')
                            isChengLe = true;
                            break;
                        }
                    }
                    if (!isChengLe) {
                        xiaobingbuzu = true;
                        myLogFunc('全体兵种不足')
                        back()
                        sleep(yanchi1)
                        back()
                        sleep(yanchi)
                    }
                }

            } else {
                myLogFunc('界面异常！')
                chaoguocaiFunc()
            }
        }
    }

}

// 采集资源出发完成
function caijiChufaFunc(bloo) {
    let thisImgs = images.read("./res/资源采集_1155_930_1337_1030.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let result = images.matchTemplate(captureScreen(), thisImgs, {  region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.88, max: 2 });
    thisImgs.recycle();
    if (result.matches.length) {
        if (result.matches.length == 1) {
            let p = result.matches[0].point;
            sleep(yanchi)
            click(p.x, p.y+5);
            sleep(yanchi3)
            log('采集出发,重读队列')
            caijiduilieFunc(true);
            sleep(yanchi1)
        } else {
            result.sortBy("left-right").matches.forEach((match,index) => {
                if (index == 0) {
                    log('match',match)
                    let p = match.point;
                    sleep(yanchi)
                    click(p.x, p.y+5);
                    sleep(yanchi3)
                    log('采集出发1,重读队列')
                    caijiduilieFunc(true);
                    sleep(yanchi1)
                }
            })
        }
    }

    if (!bloo) {
        if (shangciweizhi.x == 0) {
            let thisImgs1 = images.read("./res/上次位置.png");
            thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
            let p1 = findImage(captureScreen(), thisImgs1);
            thisImgs1.recycle();
            if (p1) {
                sleep(yanchi)
                let newObj = { x: p1.x, y: p1.y };
                storage.put("shangciweizhi", newObj);
                shangciweizhi = storage.get("shangciweizhi", { x: 0, y: 0 });
                click(p1.x, p1.y);
                sleep(yanchi5)
            }
        } else {
            click(shangciweizhi.x, shangciweizhi.y);
            sleep(yanchi5)
        }
    }

    return
}

// 屏幕资源采集
function toAllZiyuanFunc(sahngciweizhi) {
    log('采集队伍数量', caijiduiwu, duiwushangxian)
    if (caijiduiwu < duiwushangxian) {
        log('可以进入采集')
        sleep(yanchi3)
        let thisImgs = images.read("./res/ziyuan.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let thiscap = captureScreen()
        let result = images.matchTemplate(thiscap, thisImgs, { region: [100, 190, (deviceWidth - 200), (deviceHeight - 200)], threshold: 0.55, max: 10 });
        thisImgs.recycle();
        if (result.matches.length) {
            log('资源列表：', result)
            if (result.matches.length == 1) {
                myLogFunc('独立资源')
                let p = result.matches[0].point;
                // click(p.x, p.y)
                if ( !dayeClick(p.x, p.y) ) {
                    return
                }
                sleep(yanchi2)
                if (cajiAnniuFunc()) {
                    sleep(yanchi2)
                    caijiYingxiongFunc()
                    sleep(yanchi2)
                    if (!xiaobingbuzu) {
                        caijiChufaFunc(sahngciweizhi)
                        sleep(yanchi2)
                    }

                }
            } else {
                myLogFunc('多个采集点')
                let points = result.sortBy("left-right").points;
                let lastTimeXy = { x: 0, y: 0 }
                for (let index = 0; index < points.length; index++) {
                    if (caijiduiwu >= duiwushangxian) {
                        myLogFunc('采集队伍已全部派出')
                        break;
                    }
                    let match = points[index];
                    log('资源', index, match)
                    let juli = Math.abs(lastTimeXy.x - match.x)
                    let juliY = Math.abs(lastTimeXy.y - match.y)
                    if (juli < 100 && juliY < 5) {
                        myLogFunc('跳过同一个矿')
                        continue;
                    }
                    sleep(yanchi)
                    // click(match.x, match.y)
                    if ( !dayeClick(match.x, match.y) ) {
                        return
                    }
                    lastTimeXy.x = match.x;
                    lastTimeXy.y = match.y;
                    sleep(yanchi2)
                    if (cajiAnniuFunc()) {
                        sleep(yanchi2)

                        caijiYingxiongFunc()
                        sleep(yanchi2)
                        if (!xiaobingbuzu) {
                            caijiChufaFunc(sahngciweizhi)
                            sleep(yanchi2)
                        }


                    } else {
                        myLogFunc('资源位置变化')
                        continue;
                    }
                }
            }
        } else {
            myLogFunc('区域资源不可采集')

        }
    }
    log('完成当前屏幕采集')
    return caijiduiwu;
}


// 查看指定位置资源
function seeZiyuanFunc(iszhiding) {
    sleep(yanchi3)
    let thisImgs = images.read("./res/ziyuan.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let thiscap = captureScreen()
    let result = images.matchTemplate(thiscap, thisImgs, { region: [(deviceWidth / 2 - 250), (deviceHeight / 2 - 200), 500, 500], threshold: 0.6, max: 10 });
    thisImgs.recycle();
    if (result.matches.length) {
        log('资源：', result)
        if (result.matches.length == 1) {
            myLogFunc('前往采集点')
            let p = result.matches[0].point;
            click(p.x, p.y)
        } else {
            myLogFunc('区域多个采集点')
            let points = result.sortBy("left-right").points
            let lastTimeXy = { x: 0, y: 0 }
            let firstPosition = { x: 0, y: 0 }
            // myLogFunc('序列化坐标集', points)
            for (let index = 0; index < points.length; index++) {
                let match = points[index];
                log('资源', index, match)
                let juli = Math.abs(lastTimeXy.x - match.x)
                let juliY = Math.abs(lastTimeXy.y - match.y)
                if (juli < 100 && juliY < 5) {
                    myLogFunc('跳过同一个矿')
                    continue;
                }
                sleep(yanchi)
                click(match.x, match.y)
                lastTimeXy.x = match.x;
                lastTimeXy.y = match.y;

                sleep(yanchi2)
                // 如果是找点采集
                if (iszhiding) {
                    // 首次配置资源坐标位置
                    if (ziyuanZuobianWeizhi.x == 0) {
                        myLogFunc('首次配置资源坐标位置')
                        let thisImgs1 = images.read("./res/坐标背景图.png");
                        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
                        let p1 = findImage(captureScreen(), thisImgs1, { region: [0, 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
                        thisImgs1.recycle();
                        log("p1", p1)
                        if (p1) {
                            myLogFunc('资源坐标位置配置完成')
                            ziyuanZuobianWeizhi.x = p1.x + 50
                            ziyuanZuobianWeizhi.y = p1.y
                            storage.put("ziyuanZuobianWeizhi", ziyuanZuobianWeizhi);
                        }else{
                            log('资源坐标位置配置失败！')
                        }
                    }
                    sleep(yanchi2)
                    log("资源坐标位置", ziyuanZuobianWeizhi.x, ziyuanZuobianWeizhi.y)
                    let cap = captureScreen()
                    let clip = images.clip(cap, ziyuanZuobianWeizhi.x, ziyuanZuobianWeizhi.y, ziyuanZuobianWeizhi.w, ziyuanZuobianWeizhi.h);
                    let orcRes = paddle.ocrText(clip);
                    clip.recycle();
                    log("坐标截取", orcRes)
                    
                    // 如果坐标就是寻找的坐标可以跳出循环了
                    if (orcRes.length != 0) {
                        firstPosition.x = match.x;
                        firstPosition.y = match.y;

                        let xy = orcRes[0];
                        myLogFunc('坐标匹配', xy)
                        let xy0 = xy[0]
                        if (isNaN(xy0)) {
                            if (xy.includes('(') || xy.includes('（')) {
                                xy = xy.substring(1, xy.length)
                            }
                        }
                        let xy3 = xy[xy.length]
                        if (isNaN(xy3)) {
                            if (xy.includes(')') || xy.includes('）')) {
                                xy = xy.substring(0, xy.length - 1)   
                            }
                        }
                        xy = xy.replace("口", "0");
                        xy = xy.replace("日", "8");
                        let douhao = ',';
                        if (xy.includes('，')) {
                            douhao = '，';
                        }
                        if (xy.includes('.')) {
                            douhao = '.';
                        }
                        let xyArr = xy.split(douhao)
                        log('xyArr',xyArr)
                        if (toCaijiList[0].x == xyArr[0] && toCaijiList[0].y == xyArr[1]) {
                            myLogFunc('找到资源')
                            firstPosition.x = 0;
                            firstPosition.y = 0;
                            break;
                        }
                    }else{
                        log('坐标截取异常')
                    }
                    sleep(yanchi3)
                    guanbiFunc(cap)
                    cap.recycle();
                }

            }

            // 如果循环一圈因为坐标识别问题导致失败，则默认第一个坐标
            if (firstPosition.x != 0) {
                myLogFunc('备用坐标', firstPosition.x, firstPosition.x)
                sleep(yanchi)
                click(firstPosition.x, firstPosition.y)
                sleep(yanchi1)
            }

            sleep(yanchi1)
        }
        return true;
    } else {
        myLogFunc('区域资源不可采集')
        return false;
    }
}

// 通用关闭
function guanbiFunc(cap) {
    let thisImgs2 = images.read("./res/签到关闭按钮.png");
    thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
    let p2 = cap ? findImage(cap, thisImgs2) : findImage(captureScreen(), thisImgs2);
    thisImgs2.recycle();
    if (p2) {
        sleep(yanchi)
        click(p2.x + 5, p2.y + 5)
        sleep(yanchi)
    }
}


// 登陆流程
function LoginFunc() {
    myLogFunc('检测更新')
    let thisImgs2 = images.read("./res/jixuyouxi.png");
    thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
    let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.8 });
    thisImgs2.recycle();
    if (p2) {
        log(p2)
        myLogFunc('继续游戏')
        sleep(yanchi)
        click(p2.x, p2.y + 5)
        myLogFunc('等待...')
        sleep(yanchi5)
    }
    sleep(yanchi1)
    if (Boolean(storage.get("jaincedenglu", false))) {
        myLogFunc('开始登陆任务')
        log(1)
        let thisCaptureScreen = captureScreen();
        log(2)
        isLoginFunc(thisCaptureScreen).then(selectProtocol).then(loginMethodFunc).then(QqSelectAccount).then((data) => {
            log(3)
            sleep(yanchi2)
            myLogFunc('界面', gameActivity, currentActivity())
            let i = 0;
            while (gameActivity != currentActivity() && i < secureNum) {
                i++;
                sleep(yanchi1)
                myLogFunc('登陆中', gameActivity, currentActivity())

            }
            sleep(yanchi5)
            ShouyeFunc()
            myLogFunc('登陆流程Data', data)
        }).catch((error) => {
            log(31)
            myLogFunc('无需登录')
            log(32)
            myLogFunc(error)
            log(33)
            ShouyeFunc()
            log(34)
        })
    } else {
        myLogFunc('不检测登录')
        ShouyeFunc()
    }
    
}


function isLoginFunc(cap) {
    log(11)
    let thispromise = new Promise((res, rej) => {
        log(12)
        let thisImgs = images.read("./res/适龄提示.png");
        log(13)
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        log(14)
        let p = findImage(cap, thisImgs, { region: [(deviceWidth / 2), (deviceHeight / 2), (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.8 });
        log(15)
        thisImgs.recycle();
        log(16)
        if (p) {
            log(17)
            myLogFunc('未登陆界面', p)
            res(cap)
        } else {
            log(18)
            rej("未在登陆流程中！")
        }
    })
    log(19)
    return thispromise;
    log(19.1)
}

function selectProtocol_loops() {
    myLogFunc('没有找到协议,重新查询')
    sleep(yanchi1)
    let thisImgs = images.read("./res/选定协议.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.85 });
    thisImgs.recycle();
    if (p) {
        myLogFunc('选定用户协议')
        sleep(yanchi1)
        click(p.x, p.y)
        sleep(yanchi)
    }
}

function selectProtocol(cap) {
    log(20)
    let thispromise = new Promise((res, rej) => {
        log(21)
        let thisImgs = images.read("./res/选定协议.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.85 });
        thisImgs.recycle();
        if (p) {
            log(22)
            myLogFunc('选定用户协议')
            sleep(yanchi1)
            click(p.x, p.y)
            sleep(yanchi)
        } else {
            log(23)
            selectProtocol_loops()
        }
        res(cap)
    })

    return thispromise;
}

function loginMethodFunc(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs;
        if (parseInt(storage.get("denglufangshi", 0)) == 0) {
            thisImgs = images.read("./res/zqq登陆_1106_865_1420_964.png");
        } else {
            thisImgs = images.read("./res/z微信登录_507_867_703_965.png");
        }
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8 });
        thisImgs.recycle();
        if (p) {
            myLogFunc('选择登陆方式')
            sleep(yanchi1)
            click(p.x, p.y)
            sleep(yanchi)
            res('登陆方式')
        } else {
            rej("查找登陆按钮异常！")
        }
    })

    return thispromise;
}

function QqSelectAccount(params) {
    let thispromise = new Promise((res, rej) => {
        if (parseInt(storage.get("denglufangshi", 0)) == 0) {
            id("a0t").waitFor()
            sleep(yanchi1)
            let qqThisName = id("a0t").findOne().text()
            myLogFunc('用户名：' + qqThisName)
            if (qqAccountName == '') {
                id("fds").findOne().click() // 同意按钮
                sleep(yanchi1)
                id("b7p").waitFor()
                id("b7p").findOne().click()
                sleep(yanchi1)
                id("b7p").waitFor()
                id("b7p").findOne().click()
                // while (gameActivity != currentActivity()) {
                //     sleep(yanchi2)
                //     id("b7p").waitFor()
                //     id("b7p").findOne().click()
                // }

                res('QQ登陆完成')

                // for (let index = 0; index < 5; index++) {
                //     myLogFunc('currentActivity()',currentActivity())
                //     // id("b7p").waitFor()
                //     id("b7p").findOne().click()
                // }
                // myLogFunc('QQ登陆完成')

            } else {
                // 选定其他已登陆账号
                // id("asz").findOne().click()
                // sleep(500)
                // id("i4m").findOne().children().forEach(child => {
                //     let target = child.findOne(id("vrn"));
                //     if (qqAccountName == target.text()) {
                //         myLogFunc('click',target);
                //         target.click()
                //     }
                //     });
            }
        } else {
            sleep(yanchi2)
            res('Wx登陆完成')
        }
    })

    return thispromise;
}






// 主页流程
function isTrueShouye(cap) {
    log(51)
    let thispromise = new Promise((res, rej) => {
        log(52)
        let thisImgs = images.read("./res/首页挑战.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            log(53)
            myLogFunc('在游戏首页')
            sleep(yanchi1)
            let y = p.y - (150*picJizhun)
            click(p.x , y);
            sleep(yanchi2)
            shouyejinru = true;
            rej('游戏首页')
        } else {
            log(54)
            log('没有 首页挑战')
            log(55)
            res(cap)
            log(56)
        }
        log(57)
    })
    log(58)

    return thispromise;
}


function closeXinshoufuli(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/新手福利关闭_8.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('新手福利')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 新手福利关闭')
        } else {
            log('不是 新手福利')
            res(cap)
        }
    })

    return thispromise;
}

function closeXinshourenwu(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/新手任务关闭.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('新手任务')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 新手任务关闭')
        } else {
            log('不是 新手任务')
            res(cap)
        }
    })

    return thispromise;
}

function closeMeiriqiandao(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/签到关闭按钮.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs, { threshold: 0.9 }) : findImage(captureScreen(), thisImgs, { threshold: 0.9 });
        thisImgs.recycle();
        if (p) {
            myLogFunc('首页签到')
            click(p.x + 5, p.y + 5);
            sleep(yanchi)
            rej('执行 首页签到关闭')
        } else {
            log('不是 签到页面')
            res(cap)
        }
    })

    return thispromise;
}

function closeZhengzhan(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/征战关闭按钮.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('征战关闭')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 征战关闭按钮')
        } else {
            log('不是 征战页面')
            res(cap)
        }
    })

    return thispromise;
}

// 循环执行寻找主页 如果不是主页就关闭按钮 找到关闭界面的第n*2次 报异常
function ShouyeFunc(bloo) {
    myLogFunc('首页流程')
    let thisCaptureScreen = captureScreen();
    if (bloo) {
        thisCaptureScreen = false;
        log('禁止穿cap')
    }
    isTrueShouye(thisCaptureScreen).then(closeXinshoufuli).then(closeXinshourenwu).then(closeMeiriqiandao).then(closeZhengzhan).then((data) => {
        myLogFunc('不在首页流程')
        myLogFunc('进入世界模式查询')
        ShijieShouyeFunc()
    }).catch((error) => {
        myLogFunc(error)
        if (error != '游戏首页') {
            sleep(yanchi1)
            ShouyeFunc(true)
        } else {
            sleep(yanchi3)
            let enter = true;
            while (enter) {
                let thisImgs = images.read("./res/通用关闭.png");
                thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth/2), 0, (deviceWidth/2), (deviceHeight / 2)], threshold: 0.7 });
                thisImgs.recycle();
                if (p) {
                    myLogFunc('关闭')
                    click(p.x+5, p.y+5);
                    sleep(yanchi3)
                }else{
                    enter = false;
                }
            }
            // 进入世界页面
            sleep(yanchi2)
            ShijieShouyeFunc()
        }
    })
}




function isTrueShijieShouye(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/世界首页.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        log('cap', cap)
        let p = cap ? findImage(cap, thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8 }) : findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8 });
        thisImgs.recycle();
        if (p) {
            log('capp', p)
            if (shouyejinru) {
                log('从首页进入 检查我的主城')
                let thisImgs1 = images.read("./res/我的主城.png");
                thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
                let p1 = cap ? findImage(cap, thisImgs1, { threshold: 0.8 }) : findImage(captureScreen(), thisImgs1, { threshold: 0.8 });
                thisImgs1.recycle();
                if (p1) {
                    myLogFunc('世界模式首页')
                    sleep(yanchi)
                    rej('找到了世界模式首页')
                } else {
                    log('没有 世界模式我的主城')
                    res(cap)
                }   
            }else{
                myLogFunc('世界模式首页')
                sleep(yanchi)
                rej('找到了世界模式首页')
            }
        } else {
            log('没有 世界模式首页进入')
            res(cap)
        }
    })

    return thispromise;
}


function closeLiulizhenbao(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/琉璃珍宝关闭_9.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('琉璃珍宝_大')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 大琉璃珍宝关闭')
        } else {
            log('没有 大琉璃珍宝')
            res(cap)
        }
    })

    return thispromise;
}

function closeXiaoxiannv(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/小仙女关闭_8.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('小仙女')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 小仙女关闭_8')
        } else {
            log('没有 小仙女')
            res(cap)
        }
    })

    return thispromise;
}

function closeLaotoubaojian(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/宝鉴关闭.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('宝鉴')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 宝鉴关闭')
        } else {
            log('没有 玲珑宝鉴')
            res(cap)
        }
    })

    return thispromise;
}


function closeLiulizhenbaoXiao(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/琉璃珍宝关闭.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('琉璃珍宝_小')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 小琉璃珍宝关闭')
        } else {
            log('没有 小琉璃珍宝')
            res(cap)
        }
    })

    return thispromise;
}

// 单个小仙女 灯笼关闭
function closeLiulizhenbaoXiaoDl(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/琉璃珍宝关闭_小仙女.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('琉璃珍宝_小仙女')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 琉璃珍宝关闭_小仙女关闭')
        } else {
            log('没有 琉璃珍宝_小仙女')
            res(cap)
        }
    })

    return thispromise;
}

function closeHuoyuerenwu(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/活跃任务关闭.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('活跃任务')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 任务关闭')
        } else {
            log('没有 活跃任务')
            res(cap)
        }
    })

    return thispromise;
}

// 返回自己主城
function fanhuizhuchengFunc() {
    myLogFunc('返回主城')
    // 返回自己主城
    if (shangciweizhi.x == 0) {
        let thisImgs = images.read("./res/上次位置.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8 });
        thisImgs.recycle();
        if (p) {
            let newObj = { x: p.x, y: p.y };
            storage.put("shangciweizhi", newObj);
            shangciweizhi = storage.get("shangciweizhi", { x: 0, y: 0 });
        }
    }
    if (shangciweizhi.x == 0) {
        let thisImgs1 = images.read("./res/小主城.png");
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
        let p1 = findImage(captureScreen(), thisImgs1, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.85 });
        thisImgs1.recycle();
        if (p1) {
            let newObj = { x: p1.x, y: p1.y };
            storage.put("shangciweizhi", newObj);
            shangciweizhi = storage.get("shangciweizhi", { x: 0, y: 0 });
        }
    }
    let whileLoop = true;
    let rongcuoNum = 0;
    while (whileLoop) {
        let thisImgs1 = images.read("./res/我的主城.png");
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
        let p1 = findImage(captureScreen(), thisImgs1, { region: [(deviceWidth / 4), 150, (deviceWidth / 2), (deviceHeight - 200)], threshold: 0.8 });
        thisImgs1.recycle();
        if (p1) {
            whileLoop = false;
        } else {
            if (shangciweizhi.x) {
                sleep(yanchi)
                click(shangciweizhi.x, shangciweizhi.y);
                rongcuoNum = rongcuoNum + 1;
                sleep(yanchi3)
                if (rongcuoNum > secureNum) {
                    myLogFunc('返回主城受阻关闭');
                    guanbiFunc()
                }
            } else {
                whileLoop = false;
                fanhuizhuchengFunc()
            }
            
        }
    }
    myLogFunc('完成返回主城');
}

// 联盟采集
function lianmengcajiFunc() {
    // 联盟采集流程
    while (!seeLianmengFunc()) {
        yichangFanhuiFunc()
        sleep(yanchi3)
    }
    sleep(yanchi1)
    lianmengjianzhuFunc()
    sleep(yanchi1)
    let bool = qianwangziyuanFunc(0)
    if (!bool) {
        sleep(yanchi2)
        return;
    }
    sleep(yanchi2)
    let nengfouCaiji = cajiAnniuFunc(true,true)
    myLogFunc('能否采集' + nengfouCaiji )
    if (nengfouCaiji) {
        sleep(yanchi2)
        // 默认联盟负重优先
        caijiYingxiongFunc(true)
        log(123)
        sleep(yanchi2)
        log(1234)
        if (!xiaobingbuzu) {
            log(666)
            caijiChufaFunc()
            sleep(yanchi2)
        } else {
            log(888)
        }
        log(12345)
    }
    sleep(yanchi2)
}

// 采集队列1
function caijiduilieFunc(bloo) {
    log('截取区域')
    let clip = images.clip(captureScreen(), youshangDuilie.x, youshangDuilie.y, youshangDuilie.w, youshangDuilie.h);
    myLogFunc('读取队列')
    log('截图')
    // images.save(clip, "/sdcard/daoyi1.jpg", "jpg", 80);
    log('截图完成')
    let result = paddle.ocrText(clip);
    log('识别完成')
    clip.recycle();
    log('释放截图')
    result = JSON.stringify(result);
    
    log(result)
    let caijiShibie = 0;
    let zhonga = 0;
    let huia = 0;
    caijiShibie = result.match(/集/g)
    zhonga = result.match(/中/g)
    huia = result.match(/回/g)
    if (caijiShibie) {
        if (bloo) {
            caijiduiwu = caijiShibie.length

            if (zhonga||huia) {
                caijiduiwu = caijiShibie.length;
                if (zhonga) {
                    log("采集中",zhonga.length)
                }
                if (huia) {
                    myLogFunc('回城队列' + huia.length)
                    // caijiduiwu = caijiduiwu - huia.length
                }
            } else {
                if (caijiShibie.length > 1) {
                    caijiduiwu = caijiShibie.length
                    myLogFunc('采集路途中')
                } else {
                    caijiduiwu = 0
                    myLogFunc('未派出采集')
                } 
            }
            myLogFunc('采集队列' + caijiduiwu)
        } else {
            caijiduiwu = caijiShibie.length
        }
    }

    if (Boolean(storage.get("openDixi", false)) && dixiTishi) {
        let dixiNum = result.match(/敌|故|战|丹/g)
        if (dixiNum) {
            myLogFunc('敌袭 敌袭')
            if (Boolean(storage.get("dixiyuyin", false))) {
                myLogFunc('敌袭 震动')
                device.vibrate(1000*30)
            }
            if (Boolean(storage.get("dixiyuyin", false))) {
                myLogFunc('敌袭 语音')
                media.playMusic("./res/dixiyuyin.mp3");
                sleep(media.getMusicDuration());
                media.playMusic("./res/dixiyuyin.mp3");
                sleep(media.getMusicDuration());
            }
            if (Boolean(storage.get("dixiyoujian", false))) {
                myLogFunc('敌袭 邮件提醒')
                let userrEmail = storage.get("userrEmail", "")
                if (isEmailValid(userrEmail)) {
                    dixiTishi = false
                    dixitzFunc()
                }else{
                    myLogFunc('邮件地址错误')
                }
            }
        }
    }
}

function isEmailValid(email) {
    const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
    return emailRegex.test(email);
}

function dixitzFunc() {
    // 请求服务
    let req = http.postJson("http://123.60.43.199:8866/main/v1/auto/EmailNotifier", {
        activationCode: storage.get("jihuoma", ""),
        aap: "yxsXysj",
        deviceWidth: device.width,
        deviceHeight: device.height,
        brand: device.brand,
        versionCode: project.versionCode,
        release: device.release,
        sdkInt: device.sdkInt,
        androidId: device.getAndroidId(),
        fingerprint: device.fingerprint,
        startTime: new Date().getTime(),
        email: storage.get("userrEmail", "")
    });
    let rJson = req.body.json();
    if (rJson.code != 200) {
        let message = rJson.message ? rJson.message : "服务异常请联系客服！";
        toastLog(message)
        myLogFunc(message)
        sleep(yanchi1)
    } else {
        myLogFunc("已发送邮件通知！")
    }
}


// 打野队列1
function dayeduilieFunc(fanhui) {
    let clip = images.clip(captureScreen(), youshangDuilie.x, youshangDuilie.y, youshangDuilie.w, youshangDuilie.h);
    let result = paddle.ocrText(clip);
    clip.recycle();
    let result1 = JSON.stringify(result);
    log(result1)
    let taofaNum = 0;
    taofaNum = result1.match(/过|讨|时|存|寸|付/g)
    if (taofaNum) {
        dayeduiwu = taofaNum.length
        myLogFunc('存在讨伐队伍' + dayeduiwu)
    }

    if (Boolean(storage.get("openDixi", false)) && dixiTishi) {
        let dixiNum = result1.match(/敌|故|战|丹/g)
        if (dixiNum) {
            myLogFunc('敌袭 敌袭')
            if (Boolean(storage.get("dixiyuyin", false))) {
                myLogFunc('敌袭 震动')
                device.vibrate(1000*30)
            }
            if (Boolean(storage.get("dixiyuyin", false))) {
                myLogFunc('敌袭 语音')
                media.playMusic("./res/dixiyuyin.mp3");
                sleep(media.getMusicDuration());
                media.playMusic("./res/dixiyuyin.mp3");
                sleep(media.getMusicDuration());
            }
            if (Boolean(storage.get("dixiyoujian", false))) {
                myLogFunc('敌袭 邮件提醒')
                let userrEmail = storage.get("userrEmail", "")
                if (isEmailValid(userrEmail)) {
                    dixiTishi = false
                    dixitzFunc()
                }else{
                    myLogFunc('邮件地址错误')
                }
            }
        }
    }

    if (fanhui) {
        let restartTime = 0;
        for (let index = 0; index < result.length; index++) {
            let element = result[index];
            if (element.includes(':')) {
                let shortest = formatGameTime(element);
                // log('index',index)
                if (restartTime == 0) {
                    // log('index == 0')
                    restartTime = shortest;
                    log('restartTime', restartTime)
                }
    
                if (shortest < restartTime && shortest != 0) {
                    myLogFunc('较短时间:'+ element)
                    restartTime = shortest;
                }
            }
        }
        return restartTime;   
    }
}

// 领取军报
function lqjunbaoFunc() {
    myLogFunc("领取军报")
    sleep(yanchi2)
    let thisImgs = images.read("./res/军报.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { region: [0, 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.8 });
    thisImgs.recycle();
    if (p) {
        click(p.x, p.y);
        sleep(yanchi2)

        let thisImgs1 = images.read("./res/一键领取.png");
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
        let p1 = findImage(captureScreen(), thisImgs1, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8 });
        thisImgs1.recycle();
        if (p1) {
            click(p1.x + 50, p1.y + 20);
            sleep(yanchi2)
            myLogFunc("一键领取")
            click(p1.x + 50, p1.y + 20);
            sleep(yanchi2)
            let thisImgs2 = images.read("./res/签到关闭按钮.png");
            thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
            let p2 = findImage(captureScreen(), thisImgs2, { region: [0, 0, deviceWidth, (deviceHeight / 2)], threshold: 0.8 });
            if (p2) {
                click(p2.x, p2.y);
                sleep(yanchi1)
            } else {
                back()
                sleep(yanchi1)
                let thisImgs3 = images.read("./res/签到关闭按钮.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3, { region: [0, 0, deviceWidth, (deviceHeight / 2)], threshold: 0.8 });
                if (p3) {
                    click(p3.x, p3.y);
                    sleep(yanchi1)
                }
            }
        } else {
            myLogFunc("暂无军报")
            back()
            sleep(yanchi2)
        }
    }
}

// 自动征收
function zhengshouFunc() {
    sleep(yanchi1)
    myLogFunc("自动征收")
    let thisImgs = images.read("./res/天选.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { region: [0, 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.8 });
    thisImgs.recycle();
    if (p) {
        click(p.x, p.y);
        sleep(yanchi2)

        let thisImgs1 = images.read("./res/一键征收.png");
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
        let p1 = findImage(captureScreen(), thisImgs1, { region: [0, 0, deviceWidth, deviceHeight], threshold: 0.8 });
        thisImgs1.recycle();
        if (p1) {
            myLogFunc("一键征收")
            click(p1.x + 50, p1.y + 20);
            sleep(yanchi3)
            let thisImgs2 = images.read("./res/强征一次.png");
            thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
            let p2 = findImage(captureScreen(), thisImgs2, { region: [0, 0, deviceWidth, deviceHeight], threshold: 0.8 });
            thisImgs2.recycle();
            if (p2) {
                myLogFunc("目前不可征收")
                let thisImgs3 = images.read("./res/签到关闭按钮.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
                thisImgs3.recycle();
                if(p3){
                    click(p3.x, p3.y);
                    p3 = null
                    sleep(yanchi1)
                }

                sleep(yanchi1)
                let thisImgs4 = images.read("./res/天选关闭.png");
                thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                let p4 = findImage(captureScreen(), thisImgs4, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
                thisImgs4.recycle();
                if(p4){
                    click(p4.x, p4.y);
                    p4 = null
                    sleep(yanchi1)
                }
            } else {
                log("没有强征，确定征收")
                sleep(yanchi3)
                sleep(yanchi1)
                // 征收啊
                let thisImgs5 = images.read("./res/确认.png");
                thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
                let p5 = findImage(captureScreen(), thisImgs5, { region: [ 0, 0, deviceWidth, deviceHeight], threshold: 0.8 });
                thisImgs5.recycle();
                if(p5){
                    click(p5.x, p5.y);
                    p5 = null
                    sleep(yanchi1)
                }

                sleep(yanchi1)
                let thisImgs4 = images.read("./res/天选关闭.png");
                thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                let p4 = findImage(captureScreen(), thisImgs4, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
                thisImgs4.recycle();
                if(p4){
                    click(p4.x, p4.y);
                    p4 = null
                    sleep(yanchi1)
                }

            }
        } else {
            myLogFunc("自动征收页面异常")
            back()
            fanhuizhuchengFunc()
            sleep(yanchi2)
        }
    }
}

// 领取任务
function lingqurenwuFunc() {
    sleep(yanchi1)
    myLogFunc("领取任务")
    let thisImgs = images.read("./res/任务.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { region: [0, 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.8 });
    thisImgs.recycle();
    if (p) {
        click(p.x, p.y);
        sleep(yanchi1)
        let thisImgs1 = images.read("./res/领取按钮.png");
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight);
        let thisImgs5 = images.read("./res/确认.png");
        thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
        let whileLoop = true;
        while (whileLoop) {
            log('whileLoop')
            sleep(yanchi2)
            whileLoop = true
            let p1 = findImage(captureScreen(), thisImgs1, { region: [0, 0, deviceWidth, deviceHeight], threshold: 0.8 });
            if (p1) {
                myLogFunc("点击领取")
                click(p1.x + 50, p1.y + 20);
                sleep(yanchi3)
                let p5 = findImage(captureScreen(), thisImgs5, { region: [0, (deviceHeight/2), deviceWidth, (deviceHeight/2)], threshold: 0.8 });
                if(p5){
                    log('确认领取！')
                    click(p5.x, p5.y);
                    p5 = null
                    sleep(yanchi2)
                }
            }else{
                log('whileLoop false')
                sleep(yanchi2)
                whileLoop = false
                let thisImgs6 = images.read("./res/关闭任务.png");
                thisImgs6 = images.scale(thisImgs6, picJizhun, picJizhunHeight)
                let p6 = findImage(captureScreen(), thisImgs6);
                thisImgs6.recycle();
                if (p6) {
                    myLogFunc('关闭活跃任务')
                    click(p6.x, p6.y);
                    p6 = null
                    sleep(yanchi1)
                }
            }
        }
        thisImgs5.recycle();
        thisImgs1.recycle();
    }
}

// 循环执行寻找世界模式主页 如果不是主页就关闭按钮 找到关闭界面的第n*2次 报异常
function ShijieShouyeFunc() {
    myLogFunc('世界模式流程')
    sleep(yanchi5)
    let thisCaptureScreen = captureScreen();
    isTrueShijieShouye(thisCaptureScreen).then(closeLiulizhenbao).then(closeXiaoxiannv).then(closeLaotoubaojian).then(closeLiulizhenbaoXiao).then(closeLiulizhenbaoXiaoDl).then(closeHuoyuerenwu).then((data) => {
        myLogFunc('世界模式查询失败')
        ShouyeFunc();
    }).catch((error) => {
        myLogFunc(error)
        if (error != '找到了世界模式首页') {
            ShijieShouyeFunc()
        } else {
            // 进入世界流程
            myLogFunc("进入世界设定流程")
            sleep(yanchi2)

            // 任务列表 ！！！！！！
            // 采集队列识别
            caijiduilieFunc(true)
            // 领取军报
            if (Boolean(storage.get("junbao", false))) {
                lqjunbaoFunc()
            }
            // 自动征收
            if (Boolean(storage.get("tianxuan", false))) {
                if (Boolean(storage.get("zhengshou", false))) {
                    zhengshouFunc()
                }
            }
            // 领取任务
            if (Boolean(storage.get("lingqurenwu", false))) {
                lingqurenwuFunc()
            }
            // 采集任务
            if (Boolean(storage.get("caijiziyuan", true))) {
                caijiziyuanFunc()
            }

            // 扫描联盟范围
            if (Boolean(storage.get("isdaye", false))) {
                // 返回自己主城
                fanhuizhuchengFunc();
                // 打野队伍查看
                dayeduilieFunc()
                myLogFunc("进行扫描打野")
                // 主城区域野怪
                myLogFunc("主城区野怪扫描")
                yeguaisaomiaoFunc(true)
                // 附近野怪扫描
                if (Boolean(storage.get("centerZhucheng", true))) {
                    myLogFunc('附近野怪扫描')
                    // 执行上下左右 上
                    for (let index = 0; index < Number(storage.get("centerNPing", "1")); index++) {
                        swipeRandom(deviceWidth * 0.5, deviceHeight * 0.5, deviceWidth * 0.5, deviceHeight * 0.9, 1000);
                        sleep(yanchi3)
                        yeguaisaomiaoFunc()
                    }
                    // 返回自己主城
                    fanhuizhuchengFunc();
                    // 执行上下左右 下
                    for (let index = 0; index < Number(storage.get("centerNPing", "1")); index++) {
                        swipeRandom(deviceWidth * 0.5, deviceHeight * 0.5, deviceWidth * 0.5, deviceHeight * 0.1, 1000);
                        sleep(yanchi3)
                        yeguaisaomiaoFunc()
                    }
                    // 返回自己主城
                    fanhuizhuchengFunc();
                    // 执行上下左右 左
                    for (let index = 0; index < Number(storage.get("centerNPing", "1")); index++) {
                        swipeRandom(deviceWidth * 0.5, deviceHeight * 0.5, (deviceWidth - 200), deviceHeight * 0.5, 2500);
                        sleep(yanchi3)
                        yeguaisaomiaoFunc()
                    }
                    // 返回自己主城
                    fanhuizhuchengFunc();
                    // 执行上下左右 右
                    for (let index = 0; index < Number(storage.get("centerNPing", "1")); index++) {
                        swipeRandom(deviceWidth * 0.5, deviceHeight * 0.5, (200), deviceHeight * 0.5, 2500);
                        sleep(yanchi3)
                        yeguaisaomiaoFunc()
                    }
                    // 返回自己主城
                    fanhuizhuchengFunc();
                    myLogFunc("附近扫描完成")   
                }
                
                // 采集点附近打野
                if (Boolean(storage.get("caijiquyuDy", false))) {
                    myLogFunc("采集点野怪扫描")
                    for (let index = 0; index < toCaijiList.length; index++) {
                        let element = toCaijiList[index];
                        log(element)
                        sleep(yanchi)
                        seeShijieditu()
                        sleep(yanchi1)
                        goXyFunc(element.x, element.y)
                        sleep(yanchi3)
                        yeguaisaomiaoFunc()
                        sleep(yanchi1)
                    }
                    myLogFunc("采集点附近扫描完成")   
                }

                // 查看世界地图
                if (Boolean(storage.get("zuoshang", false))) {
                    myLogFunc("联盟打野-左上")
                    for (let index = 0; index < zuoshangList.length; index++) {
                        if (index < lmNontinue) {
                            continue;
                        }
                        let element = zuoshangList[index];
                        log(element)
                        sleep(yanchi)
                        seeShijieditu()
                        sleep(yanchi1)
                        goXyFunc(element.x, element.y)
                        sleep(yanchi3)
                        yeguaisaomiaoFunc()
                        sleep(yanchi1)
                    }
                }

                if (Boolean(storage.get("zuozhong", false))) {
                    myLogFunc("联盟打野-左中")
                    for (let index = 0; index < zuozhongList.length; index++) {
                        if (index < lmNontinue) {
                            continue;
                        }
                        let element = zuozhongList[index];
                        log(element)
                        sleep(yanchi)
                        seeShijieditu()
                        sleep(yanchi1)
                        goXyFunc(element.x, element.y)
                        sleep(yanchi3)
                        yeguaisaomiaoFunc()
                        sleep(yanchi1)
                    }
                }

                if (Boolean(storage.get("zuoxia", false))) {
                    myLogFunc("联盟打野-左下")
                    for (let index = 0; index < zuoxiaList.length; index++) {
                        if (index < lmNontinue) {
                            continue;
                        }
                        let element = zuoxiaList[index];
                        log(element)
                        sleep(yanchi)
                        seeShijieditu()
                        sleep(yanchi1)
                        goXyFunc(element.x, element.y)
                        sleep(yanchi3)
                        yeguaisaomiaoFunc()
                        sleep(yanchi1)
                    }
                }

                if (Boolean(storage.get("youshang", false))) {
                    myLogFunc("联盟打野-右上")
                    for (let index = 0; index < youshangList.length; index++) {
                        if (index < lmNontinue) {
                            continue;
                        }
                        let element = youshangList[index];
                        log(element, index)
                        sleep(yanchi)
                        seeShijieditu()
                        sleep(yanchi1)
                        goXyFunc(element.x, element.y)
                        sleep(yanchi3)
                        yeguaisaomiaoFunc()
                        sleep(yanchi1)
                    }
                }

                if (Boolean(storage.get("youzhong", false))) {
                    myLogFunc("联盟打野-右中")
                    for (let index = 0; index < youzhongList.length; index++) {
                        if (index < lmNontinue) {
                            continue;
                        }
                        let element = youzhongList[index];
                        log(element)
                        sleep(yanchi)
                        seeShijieditu()
                        sleep(yanchi1)
                        goXyFunc(element.x, element.y)
                        sleep(yanchi3)
                        yeguaisaomiaoFunc()
                        sleep(yanchi1)
                    }
                }

                if (Boolean(storage.get("youxia", false))) {
                    myLogFunc("联盟打野-右下")
                    for (let index = 0; index < youxiaList.length; index++) {
                        if (index < lmNontinue) {
                            continue;
                        }
                        let element = youxiaList[index];
                        log(element)
                        sleep(yanchi)
                        seeShijieditu()
                        sleep(yanchi1)
                        goXyFunc(element.x, element.y)
                        sleep(yanchi3)
                        yeguaisaomiaoFunc()
                        sleep(yanchi1)
                    }
                }


                // 方形区域打野
                if (Boolean(storage.get("changfangxingDy", false))) {
                    fangxingquyuDyFunc();
                }
            }
            
            // 返回自己主城
            fanhuizhuchengFunc();

            if (parseInt(storage.get("yunxingfangshi", 1)) == 0) {
                myLogFunc('设置-智能运行')
                let clipRestart = images.clip(captureScreen(), youshangDuilie.x, youshangDuilie.y, youshangDuilie.w, youshangDuilie.h);
                let paddleOcrRestart = paddle.ocr(clipRestart);
                clipRestart.recycle();
                let restartTime = 0;
                for (let index = 0; index < paddleOcrRestart.length; index++) {
                    let element = paddleOcrRestart[index];
                    if (element.text.includes(':')) {
                        log("paddleOcrRestart", element)
                        let shortest = formatGameTime(element.text);
                        if (restartTime == 0) {
                            restartTime = shortest;
                            log('restartTime', restartTime)
                        }

                        if (shortest < restartTime && shortest != 0) {
                            myLogFunc('较短时间:'+element.text)
                            restartTime = shortest;
                        }
                    }
                }
                let restartTimeFen = parseInt(restartTime/1000/60)
                if (restartTimeFen == 0) {
                    myLogFunc('一分钟后重新运行！')
                } else {
                    myLogFunc('最短时间:'+restartTimeFen+'分钟！')
                }
                sleep(2500)
                // 小于十分钟 采集任务
                let runAgainTime = restartTime + (1000*120)
                if (restartTimeFen < 12) {
                    myLogFunc('等待较短采集任务！')
                    let reloadTimeOut = setTimeout(() => {
                        // 重新运行
                        mainFunc()
                        clearTimeout(reloadTimeOut)
                    }, runAgainTime );
                } else {
                    // 出野怪时间配置
                    if (Boolean(storage.get("isdaye", false))) {
                        let timeArr = [3,6,9,12,15,18,24]
                        let thisTime = new Date()
                        let getHours = thisTime.getHours()
                        let getMinutes = thisTime.getMinutes()
                        log(getHours)
                        log(getMinutes)
                        let selectTime = 0;
                        for (let index = 0; index < timeArr.length; index++) {
                            let element = timeArr[index];
                            if (selectTime == 0 && (element - getHours) > 0 ) {
                                selectTime = element
                            }
                        }
                        log(selectTime)
                        selectTime = (selectTime - getHours)*60 - getMinutes;
                        log(selectTime)
                        if (restartTimeFen > selectTime) {
                            myLogFunc('智能野怪刷新时重启')
                            restartTimeFen = selectTime - 6;
                            restartTime = restartTimeFen*1000*60
                        }
                    }

                    // 长时间采集任务
                    if (restartTimeFen > 90) {
                        myLogFunc('智能时间限制')
                        restartTimeFen = 90
                        restartTime = restartTimeFen*1000*60
                    }
                    myLogFunc((restartTimeFen+6)+'分钟后重新运行！')
                    sleep(yanchi1)
                    myLogFunc('本次运行即将结束')
                    myLogFunc('即将返回主页')
                    sleep(yanchi2)
                    caijiduiwu = 0;
                    myLogStr = "";
                    floatyConsole.close()
                    sleep(yanchi1)
                    runAgainTime = restartTime + (1000*360)
                    var reloadInterval1 = 0;
                    if ( Boolean(storage.get("zhenjibaohuo", false)) ) {
                        reloadInterval1 = setInterval(()=>{
                            toastLog(' 保活')
                        },1000*60*9) // 1000*60*9
                    }
                    let reloadTimeOut1 = setTimeout(() => {
                        // 输出日志窗口
                        xuanfuLogFunc()
                        // 重新运行
                        mainFunc()
                        clearTimeout(reloadTimeOut1)
                        if (Boolean(storage.get("zhenjibaohuo", false))) {
                            clearInterval(reloadInterval1)
                        }
                    }, runAgainTime ); // runAgainTime
                    toastLog('任务配置完成！')
                    back()
                    sleep(yanchi1)
                }
                toastLog('智能运行 等待新任务')
                sleep(yanchi2)
            }else if (parseInt(storage.get("yunxingfangshi", 1)) == 1) {
                myLogFunc('设置-循环运行')
                myLogFunc('一分钟后循环运行')
                sleep(60000)
                mainFunc()
                toastLog('循环运行 等待新任务')
            }else if (parseInt(storage.get("yunxingfangshi", 1)) == 2) {
                let intermission = Number(storage.get("intermission", "1"))
                myLogFunc('设置-定时运行')
                myLogFunc('定时运行，'+intermission+'小时后启动')
                intermission = intermission*60*1000;
                caijiduiwu = 0;
                myLogStr = "";
                floatyConsole.close()
                sleep(yanchi1)
                var reloadInterval2 = 0;
                if (Boolean(storage.get("zhenjibaohuo", false))) {
                    reloadInterval2 = setInterval(()=>{
                        toastLog(' 保活')
                    },1000*60*9) // 1000*60*9
                }
                let reloadTimeOut2 = setTimeout(() => {
                    // 输出日志窗口
                    xuanfuLogFunc()
                    // 重新运行
                    mainFunc()
                    clearTimeout(reloadTimeOut2)
                    if (Boolean(storage.get("zhenjibaohuo", false))) {
                        clearInterval(reloadInterval2)
                    }
                }, intermission );
                toastLog('定时运行 等待新任务')
            }
        }
    })
}

// 智能运行循环定时
function formatGameTime(params) {
    params = params.trim()
    params = params.replace(/：/g, ":");
    if (!params.includes(':')) {
        return 0;
    }
    params = params.split(":");
    if (params.length != 3) {
        return 0;
    }
    
    let newTimeSt = (Number(params[0])*60*60 + Number(params[1])*60 + Number(params[2]))*1000;
    if (isNaN(newTimeSt)) {
        return 0;
    }
    return newTimeSt;
}

// 方形区域打野
function fangxingquyuDyFunc() {
    myLogFunc("区域打野")
    let fangxingYe = storage.get("fangxingPing", "108,88,138,108")
        log(fangxingYe)
        fangxingYe = fangxingYe.split(",")
        log(fangxingYe)
        if (fangxingYe.length == 4) {
            myLogFunc("计算区域")
            let x0 = fangxingYe[0]
            let y0 = fangxingYe[1]
            let x1 = fangxingYe[2]
            let y1 = fangxingYe[3]
            let lengthNumX = parseInt((x1-x0)/10)
            log(lengthNumX)
            let lengthNumY = parseInt((y1-y0)/8)
            log(lengthNumY)
            let quyuDyList = []
            
            for (let indexY = 0; indexY <= lengthNumY; indexY++) {
                let y = Number(y0)+(indexY*8)
                for (let index = 0; index <= lengthNumX; index++) {
                    let x = Number(x0)+(index*10)
                    quyuDyList.push({"x":x,"y":y})
                }
            }
            log('quyuDyList',JSON.stringify(quyuDyList))

            for (let index = 0; index < quyuDyList.length; index++) {
                let element = quyuDyList[index];
                log(element)
                sleep(yanchi)
                seeShijieditu()
                sleep(yanchi1)
                goXyFunc(element.x, element.y)
                sleep(yanchi3)
                yeguaisaomiaoFunc()
                sleep(yanchi1)
            }

        }else{
            myLogFunc("区域打野配置错误")
        }
}

// 去打野啊
function qudayeaFunc(ds) {
    sleep(yanchi1)
    let thisImgs = images.read("./res/讨伐按钮.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs);
    thisImgs.recycle();
    if (p) {
        myLogFunc('选择英雄', p)
        sleep(yanchi)
        click(p.x, p.y);
        sleep(yanchi2)
            // 英雄信息
            let thisImgs4 = images.read("./res/英雄信息.png");
            thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
            let result = images.matchTemplate(captureScreen(), thisImgs4, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8, max: 8 });
            thisImgs4.recycle();
            // log(result)
            if (result.matches.length) {
                if (Boolean(storage.get("shuayewushang", false))) {
                    // 无伤打野
                    let xx = 0 + Number(storage.get("shuayebaoliu", "0"))
                    let p4 = result.sortBy("left-right").matches[xx].point;
                    sleep(yanchi)
                    click(p4.x- 109, p4.y + 168.5)
                    sleep(yanchi1)
                    // 讨伐出发
                    myLogFunc('讨伐出发')
                    let thisImgs5 = images.read("./res/讨伐按钮.png");
                    thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
                    let p5 = findImage(captureScreen(), thisImgs5, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)] });
                    thisImgs.recycle();
                    if (p5) {
                        sleep(yanchi)
                        click(p5.x, p5.y);
                        sleep(yanchi2)
                        // 上次位置
                        if (ds) {
                            if (shangciweizhi.x == 0) {
                                let thisImgsS = images.read("./res/上次位置.png");
                                thisImgsS = images.scale(thisImgsS, picJizhun, picJizhunHeight)
                                let pS = findImage(captureScreen(), thisImgsS);
                                thisImgsS.recycle();
                                if (pS) {
                                    sleep(yanchi)
                                    let newObj = { x: pS.x, y: pS.y };
                                    storage.put("shangciweizhi", newObj);
                                    shangciweizhi = storage.get("shangciweizhi", { x: 0, y: 0 });
                                    click(pS.x, pS.y);
                                    sleep(yanchi5)
                                }
                            } else {
                                click(shangciweizhi.x, shangciweizhi.y);
                                sleep(yanchi5)
                            }   
                        }
                    }
                } else {
                    // 识别打野
                    // let bestMatch = {}
                    // let bestNumber = 0;
                    let needHero = false;
                    let aa = result.matches.length - 1 - storage.get("shuayebaoliu", "0");
                    result.sortBy("right-left").matches.forEach((match,indea) => {
                        if (needHero) {
                            return;
                        }
                        
                        if (indea >= aa) {
                            log('result.matches.length', result.matches.length, indea)
                            log('跳过保留')
                            return;
                        }
                        log('找合适英雄')
                        sleep(yanchi)
                        click(match.point.x - 109, match.point.y + 168.5);
                        sleep(yanchi2)
                        let thisImgs6 = images.read("./res/胜券在握.png");
                        thisImgs6 = images.scale(thisImgs6, picJizhun, picJizhunHeight)
                        let p6 = findImage(captureScreen(), thisImgs6, { region: [0, 0, deviceWidth, (deviceHeight / 2)], threshold: 0.72 } );
                        let result6 = images.matchTemplate(captureScreen(), thisImgs6, { region: [0, 0, deviceWidth, (deviceHeight / 2)], threshold: 0.6 });
                        thisImgs6.recycle();
                        log('result6',result6)
                        if (p6) {
                            log('胜券在握')
                            // 讨伐出发
                            myLogFunc('讨伐出发')
                            let thisImgs5 = images.read("./res/讨伐按钮.png");
                            thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
                            let p5 = findImage(captureScreen(), thisImgs5, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)] });
                            thisImgs.recycle();
                            if (p5) {
                                sleep(yanchi)
                                click(p5.x, p5.y);
                                sleep(yanchi2)
                                // 上次位置
                                if (ds) {
                                    if (shangciweizhi.x == 0) {
                                        let thisImgsS = images.read("./res/上次位置.png");
                                        thisImgsS = images.scale(thisImgsS, picJizhun, picJizhunHeight)
                                        let pS = findImage(captureScreen(), thisImgsS);
                                        thisImgsS.recycle();
                                        if (pS) {
                                            sleep(yanchi)
                                            let newObj = { x: pS.x, y: pS.y };
                                            storage.put("shangciweizhi", newObj);
                                            shangciweizhi = storage.get("shangciweizhi", { x: 0, y: 0 });
                                            click(pS.x, pS.y);
                                            sleep(yanchi5)
                                        }
                                    } else {
                                        click(shangciweizhi.x, shangciweizhi.y);
                                        sleep(yanchi5)
                                    }
                                }
                            }
                            needHero = true;
                        }else{
                            log("战力不足")
                        }
                    })

                    // 没有合适英雄
                    if (!needHero) {
                        myLogFunc('没有合适英雄')
                        back();
                        return false;
                    }
                    
                }
                
            }

            let thisImgs3 = images.read("./res/讨伐按钮.png");
            thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
            let p3 = findImage(captureScreen(), thisImgs3);
            thisImgs3.recycle();
            if (p3) {
                sleep(yanchi)
                click(p.x, p.y);
                sleep(yanchi1)
            }
        


    } else {
        let thisImgs1 = images.read("./res/侦查按钮.png");
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
        let p1 = findImage(captureScreen(), thisImgs1);
        thisImgs1.recycle();
        if (p1) {
            myLogFunc('不侦查野怪')
            sleep(yanchi)
            back();
            sleep(yanchi1)
        }else{
            myLogFunc("野怪定位偏差");
            let thisImgs3 = images.read("./res/别人野怪关闭.png");
            thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
            let p3 = findImage(captureScreen(), thisImgs3, { threshold: 0.88 });
            thisImgs3.recycle();
            if (p3) {
                myLogFunc("正在打野");
                sleep(yanchi)
                click(p3.x,p3.y);
                sleep(yanchi1)
                return false;
            }else{
                let thisImgs2 = images.read("./res/世界首页.png");
                thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
                let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.88 });
                thisImgs2.recycle();
                if (p2) {
                    myLogFunc('世界模式首页啊')
                    return false;
                } else {
                    myLogFunc('未知界面_打野')
                    back();
                    return false;
                }
            }
        }
    }
}
// 跳过还是等待
function dayechashuFunc() {
    // 先看有没有天选
    if (Boolean(storage.get("tianxuan", false))) {
        // 有天选先把能跳的跳了
        let myx = deviceWidth - youshangDuilie.w;
        let myy = youshangDuilie.y;
        let clip = images.clip(captureScreen(), youshangDuilie.x, youshangDuilie.y, youshangDuilie.w, youshangDuilie.h);
        let result = paddle.ocr(clip);
        clip.recycle();
        // log(result)
        result = result.reverse()
        // log('result.reverse',result)
        let onece = false;
        result.forEach(element => {
            // 从后往前跳过没问题 可以注释
            // if (onece) {
            //     return
            // }
            // log(element.text)
            let jina = element.text.match(/进|连|讲/g)
            // log(jina)
            if (jina) {
                log('进入',element.text)
                let x = myx + element.bounds.centerX();
                let y = myy + element.bounds.centerY();
                log('跳',x,y,myx,myy)
                click(x,y)
                sleep(yanchi1)
                let thisImgs3 = images.read("./res/立即跳过.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3);
                thisImgs3.recycle();
                if (p3) {
                    sleep(yanchi)
                    click(p3.x, p3.y);
                    onece = true;
                    dayeduiwu -= 1;
                    sleep(yanchi3)
                }
                sleep(yanchi3)
            }
        });
        // 再次查看有没有空队列
        let timea = dayeduilieFunc(true)
        // 如果都在回城路上
        if (dayeduiwu >= duiwushangxian) {
            // 大于五分钟 就变成一分钟
            if (timea > 300000) {
                timea = 60000
            }
            myLogFunc('等待'+parseInt(timea/1000)+'秒')
            sleep(timea+2000)
            dayechashuFunc()
        } 
    }else{
        // 没开天选
        let timea = dayeduilieFunc(true)
        if (dayeduiwu >= duiwushangxian) {
            if (timea > 600000) {
                timea = 300000
            }
            myLogFunc('等待'+parseInt(timea/1000)+'秒')
            sleep(timea+10000)
            dayechashuFunc()
        }
    }
}

// 扫描野怪
function yeguaisaomiaoFunc(buhui) {
    log('去打野啊')
    let thisImgs = null;
    let threshold = 0.78;
    let cap = captureScreen();
    let pointsAllList = []
    if (Boolean(storage.get("ye1", false))) {      
        threshold = 0.81;
        thisImgs = images.read("./res/一级野.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
        let thisResult = images.matchTemplate(cap, thisImgs, { threshold: threshold, max: 6 });
        thisImgs.recycle();
        if (thisResult.matches.length) {
            log('thisResult1',thisResult)
            let points = thisResult.sortBy("left-right").points;
            pointsAllList = pointsAllList.concat(points);
            log('pointsAllList1',pointsAllList)
        }
    }
    if (Boolean(storage.get("ye2", false))) {
        threshold = 0.82;
        thisImgs = images.read("./res/二级野.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
        let thisResult = images.matchTemplate(cap, thisImgs, { threshold: threshold, max: 6 });
        thisImgs.recycle();
        if (thisResult.matches.length) {
            log('thisResult2',thisResult)
            let points = thisResult.sortBy("left-right").points;
            pointsAllList = pointsAllList.concat(points);
            log('pointsAllList2',pointsAllList)
        }
    }
    if (Boolean(storage.get("ye3", false))) {
        threshold = 0.82;
        thisImgs = images.read("./res/三级野.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
        let thisResult = images.matchTemplate(cap, thisImgs, { threshold: threshold, max: 6 });
        thisImgs.recycle();
        if (thisResult.matches.length) {
            log('thisResult3',thisResult)
            let points = thisResult.sortBy("left-right").points;
            pointsAllList = pointsAllList.concat(points);
            log('pointsAllList3',pointsAllList)
        }
    }
    if (Boolean(storage.get("ye4", false))) {
        threshold = 0.81;
        thisImgs = images.read("./res/四级野.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
        let thisResult = images.matchTemplate(cap, thisImgs, { threshold: threshold, max: 4 });
        thisImgs.recycle();
        if (thisResult.matches.length) {
            log('thisResult4',thisResult)
            let points = thisResult.sortBy("left-right").points;
            pointsAllList = pointsAllList.concat(points);
            log('pointsAllList4',pointsAllList)
        }
    }
    if (Boolean(storage.get("ye5", false))) {
        threshold = 0.81;
        thisImgs = images.read("./res/五级野.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
        let thisResult = images.matchTemplate(cap, thisImgs, { threshold: threshold, max: 5 });
        thisImgs.recycle();
        if (thisResult.matches.length) {
            log('thisResult5',thisResult)
            let points = thisResult.sortBy("left-right").points;
            pointsAllList = pointsAllList.concat(points);
            log('pointsAllList5',pointsAllList)
        }
    }
    if (Boolean(storage.get("ye6", false))) {
        threshold = 0.81;
        thisImgs = images.read("./res/六级野.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
        let thisResult = images.matchTemplate(cap, thisImgs, { threshold: threshold, max: 4 });
        thisImgs.recycle();
        if (thisResult.matches.length) {
            log('thisResult6',thisResult)
            let points = thisResult.sortBy("left-right").points;
            pointsAllList = pointsAllList.concat(points);
            log('pointsAllList6',pointsAllList)
        }
    }
    if (Boolean(storage.get("ye7", false))) {
        threshold = 0.82;
        thisImgs = images.read("./res/七级野.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
        let thisResult = images.matchTemplate(cap, thisImgs, { threshold: threshold, max: 3 });
        thisImgs.recycle();
        if (thisResult.matches.length) {
            log('thisResult7',thisResult)
            let points = thisResult.sortBy("left-right").points;
            pointsAllList = pointsAllList.concat(points);
            log('pointsAllList7',pointsAllList)
        }
    }

        if (!thisImgs) {
            thisImgs = images.read("./res/级野.png");
            thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
            let thisResult = images.matchTemplate(captureScreen(), thisImgs, { threshold: threshold, max: 10 });
            thisImgs.recycle();
            if (thisResult.matches.length) {
                let points = thisResult.sortBy("left-right").points;
                pointsAllList = pointsAllList.concat(points);
                log('pointsAllList_all',pointsAllList)
            }
        }
        
        log("pointsAllList",pointsAllList)
        if (pointsAllList.length) {
            log('野怪数据', pointsAllList)
            if (pointsAllList.length == 1) {
                dayechashuFunc()
                myLogFunc('单野怪')
                let p = pointsAllList[0];
                if (!dayeClick(p.x, p.y)) {
                    return false;
                }
                qudayeaFunc(false)
            } else {
                myLogFunc('多野怪')
                for (let index = 0; index < pointsAllList.length; index++) {
                    let match = pointsAllList[index];
                    myLogFunc('野怪'+index, match)
                    dayechashuFunc()
                    sleep(yanchi1)
                    if (!dayeClick(match.x, match.y)) {
                        continue;
                    }

                    // // 主城位置野怪 不回去
                    if (buhui) {
                        log('不回去')
                        qudayeaFunc(false)
                    }else{
                        log('回')
                        qudayeaFunc(true)
                    }
                }
            }
        }
}

// 采集打野 - 增加安全区域控制
function dayeClick(x, y) {
    if (x<(400*picJizhun) && y < (250*picJizhun)) {
        myLogFunc('安全区限制')
        return false;
    }
    if (x>(1008*picJizhun) && y < (218*picJizhun)) {
        myLogFunc('安全区限制')
        return false;
    }
    click(x,y)
    return true;
}

// 采集资源
function caijiziyuanFunc() {
    // 联盟采集
    lianmengcajiFunc()
    // 保险再次识别
    if (caijiduiwu < duiwushangxian) {
        myLogFunc('确认队列')
        caijiduilieFunc(true)
    }
    if (!Boolean(storage.get("zhicaifujin", false))) {
        // 定点采集流程
        for (let index = 0; index < toCaijiList.length; index++) {
            if (xiaobingbuzu) {
                myLogFunc('缺乏兵力资源')
                break;
            }
            
            log('caijiduiwu', caijiduiwu)
            if (caijiduiwu >= duiwushangxian) {
                myLogFunc('已经派出全部采集')
                break;
            }
            sleep(yanchi2)
            // 查看世界地图
            seeShijieditu()

            // 点击小地图 跳转指定位置
            goXyFunc(toCaijiList[index].x, toCaijiList[index].y);
            // 区域没有可采集资源跳过本次循环
            if (!seeZiyuanFunc(true)) {
                continue;
            }
            sleep(yanchi2)

            if (cajiAnniuFunc()) {
                sleep(yanchi2)
                caijiYingxiongFunc()
                if (!xiaobingbuzu) {
                    caijiChufaFunc()
                    sleep(yanchi2)
                }
                sleep(yanchi2)
            }
            sleep(yanchi)
        }
    }


    // 备用采集
    if (!xiaobingbuzu) {
        if (caijiduiwu < duiwushangxian) {
            myLogFunc('采集队伍空缺')
            if (Boolean(storage.get("beixuanziyuan", true))) {
                myLogFunc('采集附近资源')
                fanhuizhuchengFunc();
                // 如果包含自己的资源
                if (Boolean(storage.get("baohanziji", false))) {
                    myLogFunc('先查看自己附近')
                    // 自己附近区域采集 不返回上次位置
                    toAllZiyuanFunc(true)
                }

                if (caijiduiwu < duiwushangxian) {
                    // 执行上下左右 上
                    for (let index = 0; index < Number(storage.get("beixuanziyuanFw", "3")); index++) {
                        swipeRandom(deviceWidth * 0.5, deviceHeight * 0.5, deviceWidth * 0.5, deviceHeight * 0.9, 1000);
                        sleep(yanchi2)
                        // 新视野区域采集
                        toAllZiyuanFunc()
                    }
                    fanhuizhuchengFunc();
                }


                if (caijiduiwu < duiwushangxian) {
                    // 执行上下左右 下
                    for (let index = 0; index < Number(storage.get("beixuanziyuanFw", "3")); index++) {
                        swipeRandom(deviceWidth * 0.5, deviceHeight * 0.5, deviceWidth * 0.5, deviceHeight * 0.1, 1000);
                        sleep(yanchi2)
                        // 新视野区域采集
                        toAllZiyuanFunc()
                    }
                    fanhuizhuchengFunc();
                }


                if (caijiduiwu < duiwushangxian) {
                    // 执行上下左右 左
                    for (let index = 0; index < Number(storage.get("beixuanziyuanFw", "3")); index++) {
                        swipeRandom(deviceWidth * 0.5, deviceHeight * 0.5, (deviceWidth - 200), deviceHeight * 0.5, 2500);
                        sleep(yanchi2)
                        // 新视野区域采集
                        toAllZiyuanFunc()
                    }
                    fanhuizhuchengFunc();
                }

                if (caijiduiwu < duiwushangxian) {
                    // 执行上下左右 右
                    for (let index = 0; index < Number(storage.get("beixuanziyuanFw", "3")); index++) {
                        swipeRandom(deviceWidth * 0.5, deviceHeight * 0.5, (200), deviceHeight * 0.5, 2500);
                        sleep(yanchi2)
                        // 新视野区域采集
                        toAllZiyuanFunc()
                    }
                    fanhuizhuchengFunc();
                }
            }
        }
    }
}
